Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
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