SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jul 2007
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript redirect not working with enter key

    Greetings,

    I have a script that submits a bid and currently have it working when pressing the submit button or pressing the enter key. Everything works perfectly while pressing the button, but it works halfway when pressing the enter key.

    When I press the enter key, the proper information gets validated, the alert window pops up as normal, information passes, but it won't redirect using:
    Code:
    document.location = url;
    When using the enter key, everything in the script works (validation and everything), it just won't redirect. It's strange.

    Please let me know why this isn't working.

    Thanks
    Kind regards

    EDIT: I also tried to add the following javascript code into the bidding text box where the price gets entered:

    Code:
    onkeydown="if (event.keyCode == 13) document.getElementById('bidsubmit').click();"
    This makes the JavaScript validation happen twice if I hit that enter key.

  2. #2
    SitePoint Addict
    Join Date
    Jul 2007
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, I figured it out sorta...

    Seems like clicking the button (<input type="button" onclick="validate();" />) field made the onclick() function work properly and redirected to the final URL that was given in the validation script.

    Pressing the enter key triggered a click on the <input type="button" onclick="validate();" /> button and went through the validation, but redirected to the <form action="URL"> instead of the URL given at the end of the validation script.

    I removed the <form></form> tags and just left <input> fields instead. Seems to validate W3C correctly and work correctly in every way now.

    Thanks for looking.

    Kind regards

  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't know what the page looks like, but you don't need to remove form tags. You can just remove the action and, if needed, place it wthin the validation function:

    <input type="button" onclick="doValidate(this.form)">

    function doValidate(formObj) {
    var ok2Send = true;
    ...validation code that set above var to false if failure
    if (ok2Send) {
    formObj.action = "dkdkdkk";
    formObj.method = ",d,d,"
    formObj.submit():
    }
    }
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

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