Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Adding Numbers


  • Please log in to reply

#1
wburrough

wburrough

    Member

  • Member
  • PipPip
  • 43 posts
ok i am just learning java and this is probally a very simple question but i cant seem to get the code to add a number to another. I have a text box which we will call the value, say the value is 300. how do i add 20. Everytime i try to do this i will come up with 30020. here is the code i have

function goldteeth (form) {
var price =form.price.value;

if (price == "1")
form.total.value = 200

else if (price == "2")
form.total.value = 300

else if (price == 3)
form.total.value = 400
}
 
function cleet (form) {

if (form.kit.value = "2")
form.total.value = form.total.value + 20
}
</script>

also here is a site with the program i tried to make. My Webpage
  • 0

Advertisements


#2
Phil

Phil

    IRC Chat Staff

  • IRC Chat Staff
  • 21 posts
You're adding 20 to the string 300 as opposed to the integer value 300.

Just change

form.total.value = form.total.value + 20

to

form.total.value = parseInt(form.total.value) + 20

~Phil~

Edited by Phil, 31 January 2007 - 03:22 PM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP