CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   Using JavaScript to Simulate Enter (http://www.codingforums.com/showthread.php?t=232305)

Seb Meikle 07-19-2011 12:00 AM

Using JavaScript to Simulate Enter
 
Is it possible to use JavaScript to automatically press the Enter key when a textfield's value is changed? I'm guessing I would need to call the function using onChange="functionexample".

After some research I found out the the map number for the Enter key is 13. I think this is the number JavaScript needs, I could be wrong.

rnd me 07-19-2011 05:48 AM

why do you want to press enter?

Seb Meikle 07-19-2011 05:59 PM

I have a form which has a section to choose a door number, each numeral is charged at £2.00. I have a script that calculates the amount of digits and that value is placed in a textfield.

I also have another textfeild that shows the total value of the order, but the problem is that the total value won't update when the amount of digits changes. If you click in the field with the amount of digits and press enter it updates the total value.

This was just a way round it I could think of.

rnd me 07-19-2011 07:52 PM

i ask because pressing enter usually triggers a form submit or onchange event.
if that's the case, you can simply call form.submit() or input.onchange() - no reason to fake key presses...



in other words, just do what enter does, don't do enter.

post the code if you need a hand.

Seb Meikle 07-20-2011 06:00 PM

Ah I see.

Just need to clarify where I should call this function?

Should it be on:
  • The textfield with the amount of digits?
  • The textfeild with the total value?
  • The form itself?

I was going to post the code, but it's too long. If you really need it to help me I will upload a text file.


All times are GMT +1. The time now is 07:42 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.