Javascript function call from file -
so...my homework says...
create function named calcbmi()
performs calculation using values in weight , height text boxes , assign result bmi text box. convert value integer number using parseint() function. reference text boxes within function using documentobject.getelementbyid(name), , value attribute of each text box (in other words, don’t use function arguments aka pass values function). add event listener to call calcbmi() function
i have done here. keep in mind javascript file being reference in html. whenever press calculate button nothing happens.
function calcbmi() { var weight = parseint(documentobject.getelementbyid("weight")); var height = parseint(documentobject.getelementbyid("height")); var result = (weight * 703) / (height * height); var textbox = documentobject.getelementbyid('result'); textbox.value = result; } document.getelementbyid("submit"). addeventlistener("click", calcbmi(), false);
i see 3 things:
- accessing dom object rather value
- using
documentobject
ratherdocument
- invoking function instead of passing callback.
here's resolve dom element issue:
var weight = parseint(document.getelementbyid("weight").value)
use same other variables.
it looks may invoking calcbmi() rather passing callback calcbmi
.addeventlistener("click", calcbmi, false);
check out mdn on event listeners
it looks referencing documentobject
rather document
.
var textbox = documentobject.getelementbyid('result');
try this:
var textbox = document.getelementbyid('result');
hope helps!
Comments
Post a Comment