Want Enter key to fire function

Results 1 to 2 of 2

Thread: Want Enter key to fire function

  1. #1
    Join Date
    Dec 1969

    Default Want Enter key to fire function

    I have a modal dialog window that only displays a select. User clicks on desired element in list and it fires function which returns the value to the parent page. I would like the same thing to happen if the user "arrows" down and hits ENTER on the desired element.. but alas my paltry coding skills are not enough

  2. #2
    Join Date
    Dec 1969

    Default well, you could consider...

    using the OnKeyUp event to test for the pressed key&#039;s Unicode. I&#039;ve never used this so I don&#039;t know if it&#039;s universally supported, or whether it always returns the same results.<BR><BR>I think the code for Enter is 13. So you could do this function in the head tag:<BR><BR>&#060;script type="text/javascript"&#062;<BR>function enterPressed()<BR>{<BR>if (event.keyCode == "13")<BR>{*** test for what&#039;s selected in your select box ****;<BR>****** fire your function here *****<BR>}<BR>}<BR>&#060;/script&#062;<BR><BR><BR>Then wherever you need to do this, just do <BR><BR>onKeyUp = "enterPressed()"<BR><BR>Trouble with this is that I&#039;ve never used this, or indeed had cause to use OnKeyUp. So this might be bollocks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts