I am trying to use an HTML button to call a JavaScript function.
Here\'s the code:
silly way:
onclick="javascript:CapacityChart();"
You should read about discrete javascript, and use a frameworks bind method to bind callbacks to dom events.
I would say it would be better to add the javascript in an un-obtrusive manner...
if using jQuery you could do something like:
<script>
$(document).ready(function(){
$('#MyButton').click(function(){
CapacityChart();
});
});
</script>
<input type="button" value="Capacity Chart" id="MyButton" >
Just so you know, the semicolon(;) is not supposed to be there in the button when you call the function.
So it should just look like this: onclick="CapacityChart()"
then it all should work :)
Your HTML and the way you call the function from the button look correct.
The problem appears to be in the CapacityCount
function. I'm getting this error in my console on Firefox 3.5: "document.all is undefined" on line 759 of bendelcorp.js.
Edit:
Looks like document.all
is an IE-only thing and is a nonstandard way of accessing the DOM. If you use document.getElementById()
, it should probably work. Example: document.getElementById("RUnits").value
instead of document.all.Capacity.RUnits.value