www.webdeveloper.com
Results 1 to 1 of 1

Thread: Enter key press execute button click

  1. #1
    Join Date
    Jun 2007
    Location
    Manchester
    Posts
    10

    Enter key press execute button click

    Hi there

    I have the code bellow on a page where I want when a user hits enter it execute the code of button click, but when I press enter it behave like a submit button. If I remove the tags "<form> & </form>" it does work on ie only.
    Does anyone can help me please?

    <html>
    <script>
    function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
    ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
    ro = new XMLHttpRequest();
    }
    return ro;
    }

    var http = createRequestObject();

    function stteam1(str1) {
    http.open('get', 'test2.asp?id='+escape(str1)+'&'+Math.random()*Math.random());
    http.onreadystatechange = handlestteam1;
    http.send(null);
    }

    function handlestteam1() {
    if(http.readyState == 4){
    var response = http.responseText;
    var update = new Array();

    if(response.indexOf('|' != -1)) {
    update = response.split('|');
    document.getElementById("posi1").innerHTML = update[0];
    }
    }
    }
    </script>
    <body>
    <form>
    <input type="text" name="n" autocomplete="off" onkeypress="if (event.keyCode == 13) stteam1(n.value);" />
    <input type="button" value="Search" onClick="stteam1(n.value);">
    </form>
    <div id="posi1"></div>
    </body>
    </html>

    Thanks
    Last edited by jony; 12-28-2012 at 11:46 AM.

Thread Information

Users Browsing this Thread

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

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