javascript math

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
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

Something like this should do the trick:

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

bruce barker

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)
 
M

Mark Rae [MVP]

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top