Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Reworking Code so that Enter works

    I am currently using the below code for a gadget on my site

    <form onsubmit="return false;" action="#">
    <onsubmit='return>
    <input style="width: 214px; height: 21px;" name="urlField" size="25" type="text" /> <input id="goBtn" value="Enter" type="button" />
    </onsubmit='return></form>
    <script type="text/javascript">
    document.getElementById( 'goBtn' ).onclick = function()
    {
    location.href = "http://www.XXXXXX.com/2000/01/work-" + this.form.urlField.value.toLowerCase() + ".html";
    }
    </script>

    However, I have had to disable the enter function through the onsubmit return false because it does not function in the same way as when clicking the enter button. Is there an easy way to retain functionality but to make pressing enter on the keyboard work in the same way as clicking the enter button?

    Thanks

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,517
    Thanks
    3
    Thanked 506 Times in 493 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    <body>
    <script> vic=0; </script>
    <form name=Show id=Show style="position:absolute;visibility:visible;top:700px;left:0px;" action="http://www.vicsjavascripts.org.uk/">
    <input size=100 name=Show0 >
    <input size=10 name=Show1 >
    <input size=10 name=Show2 >
    <input size=10 name=Show3 >
    <input size=10 name=Show4 >
    <input size=10 name=Show5 >
    <input size=10 name=Show6 >
    <input size=10 name=Show7 >
    <input size=10 name=Show8 >
    <input size=10 name=Show9 ><br>
    <textarea name=TA rows=1 cols=100 ></textarea>
    </form>
    <script type="text/javascript">
    /*<![CDATA[*/
    function KeyCode(e){
     e=e||window.event;
     var charCode=e.which?e.which:event.keyCode ;
     if (charCode==13){
      document.Show.submit();
     }
     return false;
    }
    document.onkeypress=function(evt){ KeyCode(evt); }
    document.onkeydown=function(evt){  KeyCode(evt); }
    /*]]>*/
    </script>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    No need to wrap inside anonymous function. The event object is automatically passed.
    Code:
    document.onkeypress = KeyCode;
    document.onkeydown = KeyCode;
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New Coder
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi there,

    I am currently using the blogger platform and the code would go under the 'gadget section'. Because of this I can only add script/basic html.

    Cheers

  • #5
    New Coder
    Join Date
    Oct 2012
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Any thoughts?


  •  

    Posting Permissions

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