Results 1 to 5 of 5

Thread: Enter key press execute button click

Threaded View

  1. #1
    Join Date
    Jun 2007

    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?

    function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
    ro = new ActiveXObject("Microsoft.XMLHTTP");
    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;

    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];
    <input type="text" name="n" autocomplete="off" onkeypress="if (event.keyCode == 13) stteam1(n.value);" />
    <input type="button" value="Search" onClick="stteam1(n.value);">
    <div id="posi1"></div>

    Last edited by jony; 12-28-2012 at 12:46 PM.

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