javascript math

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,
in javascript, how do i take the value in a textbox and add that to a number
to get a sum result?
thanks,
rodchar
 
Something like this should do the trick:

var a = document.getElementById('mytextboxclientid').value + 10;
alert(a);
 
not quite right, this will do string concatenation because of
precedence. try:

var e = document.getElementById('<%=mytextbox.ClientID%>');
var a = new Number(e.value) + 10;

-- bruce (sqlwork.com)
 
Something like this should do the trick:

var a = document.getElementById('mytextboxclientid').value + 10;
alert(a);

No it won't - you've forgotten to tell JavaScript to treat the contents of
the TextBox as a number:

var a = parseInt(document.getElementById('mytextboxclientid').value) + 10;
alert(a);
 
Back
Top