if i have three text boxes and i want to add the 3 values togeather and say if they are greater than a certain number. How would i go about doing this.
Well firstly, since they are input as Strings - you will need to convert them to Numbers. If you do not, they will be added together like strings (concatenated) - meaning 1+2=12.
function add(form){
var No1 = new Number(form.v1.value);
var No2 = new Number(form.v2.value);
var No3 = new Number(form.v3.value);
var answer = No1+No2+No3;
form.answer.value = answer;
if(answer > 10){
alert("Numbers add to more than 10"
}
}
Where the function is called from a buton like this:
And the v1,v2,v3 are just the names of the three text fields for input.
The this.form attribute holds the form object for the element we call it on - in this case the button - so we are sending the function the complete form object to operate on. ;-)
b2 - benbiddington@surf4nix.com
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.