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.
The TypeError: "x" is not a function can be fixed using the following suggestions: Paying attention to detail in code and minimizing typos. Importing the correct and relevant script libraries used in code. Making sure the called property of an object is actually a function.
onclick is not a function" error occurs, because there is no onclick() function in jQuery. To solve the error, use the click function instead, e.g. $('#btn'). click(function () {} . Copied!
The TypeError object represents an error when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type. A TypeError may be thrown when: an operand or argument passed to a function is incompatible with the type expected by that operator or function; or.
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value is not actually a function.
Please change only the name of the function; no other change is required
<script> function totalbandwidthresult() { alert("fdf"); 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; alert(totalbandwidth); document.calculator.totalbandwidthresult.value = totalbandwidth; } </script> <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="totalbandwidthresult();"> </form>
Since the behavior is kind of strange, I have done some testing on the behavior, and here's my result:
If you are:
form
, andonclick="xxx()"
on an elementid="xxx"
or name="xxx"
to that element Here's are some test and their result:
function totalbandwidth(){ alert("Total Bandwidth > 9000Mbps"); }
<form onsubmit="return false;"> <button onclick="totalbandwidth()">SUCCESS</button> </form>
function totalbandwidth(){ alert("Total Bandwidth > 9000Mbps"); }
<form onsubmit="return false;"> <button id="totalbandwidth" onclick="totalbandwidth()">FAILED</button> </form>
function totalbandwidth(){ alert("Total Bandwidth > 9000Mbps"); }
<form onsubmit="return false;"> <button name="totalbandwidth" onclick="totalbandwidth()">FAILED</button> </form>
function totalbandwidth(){ alert("Total Bandwidth > 9000Mbps"); }
<form onsubmit="return false;"> <input type="button" value="totalbandwidth" onclick="totalbandwidth()" />SUCCESS </form>
function totalbandwidth(){ alert("Total Bandwidth > 9000Mbps"); }
<button id="totalbandwidth" onclick="totalbandwidth()">SUCCESS</button>
function totalbandwidth(){ alert("The answer is no, the span will not affect button"); }
<form onsubmit="return false;"> <span name="totalbandwidth" >Will this span affect button? </span> <button onclick="totalbandwidth()">SUCCESS</button> </form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With