Page 1 of 1

Javascript and html input

Posted: Sun Jun 18, 2006 9:56 am
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.

Posted: Sun Jun 18, 2006 12:18 pm
by Weirdan
It's usually done on keyup event

Posted: Sun Jun 18, 2006 12:40 pm
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.