Edit: Here's a JSfiddle
Edit2: The error is on this line: <input type="button" value="totalbandwidthresult" onclick="javascript:totalbandwidth();">
Trying to have a button perform a calculation. The required variables are below, as well as the HTML where
I am getting an error onclick: Uncaught TypeError: object is not a function index.html:71
onclick
Here is my Javascript
function totalbandwidth() {
var fps=Number(document.calculator.fps.value);
var bitrate=Number(document.calculator.bitrate.value);
var numberofcameras = Number(document.calculator.numberofcameras.value);
var encoding = document.calculator.encoding.value;
if (encoding = "mjpeg")
{
storage = bitrate*fps;
}
else
{
storage = bitrate;
}
totalbandwidth = (numberofcameras * storage) / 1000;
document.calculator.totalbandwidthresult.value = totalbandwidth;
}
The HTML:
<form name="calculator" class="formtable">
<div class="formrow"><label for="rcname">RC Name</label> <input type="text" name="rcname"></div>
<div class="formrow"><label for="fps">FPS</label> <input type="text" name="fps"> </div>
<div class="formrow"><label for="bitrate">Bitrate</label> <input type="text" name="bitrate"> </div>
<div class="formrow"><label for="numberofcameras">Number of Cameras</label> <input type="text" name="numberofcameras"> </div>
<div class="formrow"><label for="encoding">Encoding</label> <select name="encoding" id="encodingoptions">
<option value="h264">H.264</option>
<option value="mjpeg">MJPEG</option>
<option value="mpeg4">MPEG4</option>
</select></div>
Total Storage: <input type="text" name="totalstorage">
Total Bandwidth: <input type="text" name="totalbandwidth">
<input type="button" value="totalbandwidthresult" onclick="javascript:totalbandwidth();">
Basically - it seems that there may be something wrong with the syntax I used in the JS - but I'm not sure.
Please change only the name of the function; no other change is required
Since the behavior is kind of strange, I have done some testing on the behavior, and here's my result:
TL;DR
If you are:
form
, andonclick="xxx()"
on an elementid="xxx"
orname="xxx"
to that elementHere's are some test and their result:
Control sample (can successfully call function)
Add id to button (failed to call function)
Add name to button (failed to call function)
Add value to button (can successfully call function)
Add id to button, but not in a form (can successfully call function)
Add id to another element inside the form (can successfully call function)
I was able to figure it out by following the answer in this thread: https://stackoverflow.com/a/8968495/1543447
Basically, I renamed all values, function names, and element names to different values so they wouldn't conflict - and it worked!