Unable to multiply without pressing button

This is a discussion on "Unable to multiply without pressing button" within the JavaScript Forum section. This forum, and the thread "Unable to multiply without pressing button are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Sep 23rd, 2007, 10:53
New Member
Join Date: Sep 2007
Location: New Delhi
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unable to multiply without pressing button

Dear friends,
I have two textboxes

<input type="text" name="price" size="20">
<input type="text" name="quantity" size="20">

In the price textbox the price is already entered. I want to automatically calculate total price by multiplying
price * quantity without pressing of calculate button (if one entered 1 in quantity it will automatically get
multiplied with price and get entered into third box, if it adds 0 with 1 i.e. 10 it target box autmatically updated).
It should also checkthe quantity only contain number.
I have trried a lot but failed. Please give any hint idea or code.
Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Sep 23rd, 2007, 12:41
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Unable to multiply without pressing button

what about calling the function onChange()
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 1st, 2007, 11:25
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up Re: Unable to multiply without pressing button

You could right a function that is called onchange or onkeyup in the quantity box.

It can do the checking for you

Code: Select all
<script type="text/javascript">

function updateAndCheck(quant, price, total)

{
    price = document.getElementById(price);
    total = document.getElementById(total);

    if (!isNaN(parseInt(quant.value)))
       total.value = (parseInt(price.value) * parseInt(quant.value));
    else {
       alert ("Numbers only please!")
       quant.value= '';
    }
}

</script>
<input type="text" name="price" size="20" id="price" />
<input type="text" name="quantity" value="" onkeyup="updateAndCheck(this, 'price', 'total')" id="quantity" size="20" />
<input type="text" name="total" value="" id="total" />
That will perform the necessary calculations and checks when the user has typed something in the box. No need to push a button at all.

Cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Send variable by pressing hyperlink? skuliaxe PHP Forum 9 Feb 6th, 2008 18:02
unable to set padding tox0tes Web Page Design 5 Jul 1st, 2007 16:45
[XSLT]: Recursive Function to Add/Multiply ThyGizmo Other Programming Languages 0 Oct 9th, 2006 08:15
Two form actions on pressing submit button? AndyP Web Page Design 7 Jul 25th, 2005 16:25
Unable to get correct leading Audioz Web Page Design 4 Nov 14th, 2004 19:32


All times are GMT. The time now is 22:19.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42