Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Adding textboxes together and displaying the result in another
Old 05-14-2009, 04:59 AM Adding textboxes together and displaying the result in another
Average Talker

Posts: 16
Trades: 0
Hi all.

I have a form with 5 text boxes for the user to enter numbers. I would like to have a sixth text box at the end that adds up the total of all the other inputs.

I assume that this can be done and will require javascripting or AJAX? The page is built in php and ideally I would like it to be done without the page reloading, hence the javascript.

Thanks,
Dan
superdan_35 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-18-2009, 05:26 PM Re: Adding textboxes together and displaying the result in another
Novice Talker

Posts: 13
Trades: 0
Hi, no need to use Ajax as you do not want to pull anything from the server.

You need to write a function which fills up the 6th textbox:

Code:
function fillSixth(){
  document.getElementById('TextBox2').value = 
  String(
    parseFloat(document.getElementById('TextBox1').value) +
    parseFloat(document.getElementById('TextBox2').value) + ...)
}
And you need to call this function when any of the first five textboxs' content changes or when the user clicks a button:
Code:
 onchange='fillSixth();'
__________________
My ITwiw profile:
Please login or register to view this content. Registration is FREE

You can use your
Please login or register to view this content. Registration is FREE
profile as a virtual name card anywhere on the web.
itwiw is offline
Reply With Quote
View Public Profile
 
Old 05-19-2009, 06:05 AM Re: Adding textboxes together and displaying the result in another
Average Talker

Posts: 16
Trades: 0
Thanks very much for your help.

Worked perfectly!

Dan
superdan_35 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Adding textboxes together and displaying the result in another
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17734 seconds with 12 queries