SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    lisboa
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using enter key to submit form

    hi
    i browsed forums but coudnt get help
    i posted this at html forum:
    this code is from one of KYank's articlesinput type="submit" name="submitquery" value="Ver (Alt+S)" accesskey="S" />
    I want it changed in a way that i can submit the form pressing the enter button. How can i achieve it?
    and got this:
    enter to submit a form is only default within a text input or password input. you'll need to add an onkeypress event to the window, and check if the keyCode or charCode == 13.
    How do i do it?
    thanks
    EDIT:
    its a textarea

  2. #2
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <form onkeypress="if(window.event.keyCode==13){this.submit()};">
    </form>

  3. #3
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that will only work in IE.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  4. #4
    SitePoint Evangelist
    Join Date
    Apr 2003
    Location
    lisboa
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot
    but i forgot to say that i've a select box too, so when i submit cliking in enter, the select box resets when the new page appears...
    better post the hole code:

    <form action="<?=$_SERVER['PHP_SELF']?>" method="POST" onkeypress="if(window.event.keyCode==13){this.submit()};">
    <p>Base de dados:
    <select name="db">
    <?php
    $dbs = mysql_list_dbs();
    for ($i=0;$i<mysql_num_rows($dbs);$i++) {
    $dbname = mysql_db_name($dbs,$i);
    if ($dbname == $db)
    echo("<option selected>$dbname</option>\n");
    else
    echo("<option>$dbname</option>\n");
    }
    ?>
    </select>
    </p>
    <p>SQLbr />
    <textarea cols="60" rows="5" name="query"><?=htmlspecialchars($query)?></textarea>
    </p>
    <p><input type="submit" name="submitquery" value="Ver" /></p>
    </form>


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
  •