Javascript and html input

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Dr.Goodvibes
Forum Newbie
Posts: 19
Joined: Wed May 24, 2006 10:14 am
Location: New Zealand

Javascript and html input

Post by Dr.Goodvibes »

I am using the following input for a numerical value which is the quantity of items to be purchased. This value is then used to create the total price.

Code: Select all

echo "<input id='myQty' type='text' name='qty' value='".$qty."' />";
The problem is, how do I update the value and have javascript detect the onChange.

i.e. I have an existing quantity of 5 and I want to increase it to 7. I then want the total price to increase to reflect the change. This is all done without having to click on an update button.

Using javascript onChange only works when the input 'box' no longer has focus.
I have used the html select and option field. This works OK with javascript onChange, but is limited to the number of values you make selectable within the options field. I would like the client to select the value.

Do I need to start looking at an onload function to continually monitor input to this field. Or is it possible to engineer the focus of the input field so that it will fire on value change?

Thanks for any advice in advance.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

It's usually done on keyup event
Dr.Goodvibes
Forum Newbie
Posts: 19
Joined: Wed May 24, 2006 10:14 am
Location: New Zealand

Post by Dr.Goodvibes »

Cool. Thank you.

That seems to work. May have to vet the keys as don't need any actions on delete and backspace. Should keep me busy for a few minutes ;-)

Thanks again.
Post Reply