www.webdeveloper.com
Results 1 to 5 of 5

Thread: onkeyPress event with Intro key doesn't work on Firefox

  1. #1
    Join Date
    Jan 2012
    Posts
    3

    onkeyPress event with Intro key doesn't work on Firefox

    Hello!!

    I am having a problem on firefox.
    I have an event (onkeyPress) on a textarea, which should trigger a function when the key pressed is Intro.
    I would have the following on HTML:
    HTML Code:
    ..
    <textarea id="idtextarea" onkeyDown="showUser(this.value)"></textarea>
    ...
    In Javascript:

    [Javascript]
    function showUser(this.value)
    {
    var keycode;
    if(window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13)
    {
    ...



    [/Javascript]

    It works on the main browsers but Firefox. Nothing happens on this browser.

    I would appreciate any help.
    Thank you very much.

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    Try this
    HTML Code:
    <head>
    <script>
    function showUser(e){ alert(e)
    	var keycode=e.which?e.which:e.keyCode;
    	alert(keycode);
    }
    </script>
    </head>
    <body>
    <textarea id="idtextarea" onkeyDown="showUser(event)"></textarea>
    </body>

  3. #3
    Join Date
    Jan 2012
    Posts
    3
    Thank you 007julien.
    I have tried. It displays an alert.
    But I don't know how to link that to my function. And couldn't I keep the (str)?
    Because after what I have written above I try to find out (in the function) wheter that value is empty or not :

    HTML Code:
    ...
    function showUser(str)
    {
    var keycode;
    if(window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13)
    {
    if(str=="")
      {
    function showUser(str)
    {
    var keycode;
    if(window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13)
    {
    var xmlhttp;
    if(str=="")
      {
    ....

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    You can keep the string with a
    HTML Code:
    <textarea id="idtextarea" onkeyDown="showUser(this.value,event)"></textarea>
    And a script
    Code:
    <script type="text/javascript">
    function showUser(str,e){ 
    	var keycode=e.which?e.which:e.keyCode;
    	// To see what you get and to comment (//) or remove after debugging 
    	alert('The string '+str+'\nThe keyCode'+keycode);
    	// do something with str and keycode
    	// ...
    }
    </script>

  5. #5
    Join Date
    Jan 2012
    Posts
    3
    thank you very very much 007Julien.
    It works fine!!

    Regards

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles