Add option to press Enter key (for Dummies)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • donomuch
    New Member
    • Nov 2008
    • 2

    Add option to press Enter key (for Dummies)

    I have a form where user enters a password text, then has to click the Submit Password button. How do I add the option to press Enter key to call the same function 'goForit'?

    I read similar posts/replies, but I don't know enough to make it work for me. I got this form and script from a free sript site. Trying to learn...thahks in advance for any help.

    here is the code:
    [html]
    <html>
    <head>
    <SCRIPT LANGUAGE="JavaS cript">
    <!-- Begin

    function goForit() {
    var location;
    var password;
    password=this.d ocument.testfor m.inputbox.valu e
    location=passwo rd + ".asp"
    fetch(location)
    theKeeper=windo w.close()
    }
    function fetch(location) {
    var root;
    if (opener.closed) {
    root=window.ope n('','theKeeper sGopher','toolb ar=yes,location =yes,status=yes ,menubar=yes,sc rollbars=yes,re sizable=yes,cop yhistory=no');
    root.location.h ref = location;
    } else {
    opener.location .href = location;
    }
    }
    // End -->
    </SCRIPT>
    </head>
    <body onLoad="top.win dow.focus()" BACKGROUND="ima ges/gatekeeper_mana gers1.jpg">

    <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
    <TR>
    <TD ROWSPAN=2 WIDTH=200px><im g src="../images/clear_1px.gif" width="200px" height="1">
    <TD WIDTH=50% ALIGN=CENTER VALIGN=MIDDLE class="maintext " style="color: #ffffff;">
    <p>&nbsp;</p>
    <p>Please enter your Password. If you do not have one, contact your Manager for
    Assistance.
    <BR>
    </p>
    <TR>
    <TD WIDTH=50% ALIGN=CENTER VALIGN=BOTTOM>
    <p>&nbsp</p>
    <CENTER>
    <FORM NAME="testform" >
    <INPUT TYPE="text" NAME="inputbox" VALUE="" size=20>
    <INPUT TYPE="button" NAME="button" Value="Submit Password" onClick="goFori t(this.form)">
    </FORM>
    </CENTER>
    </TABLE>
    </body>
    </html>
    [/html]
    <!-- Script Size: 1.71 KB -->
    Last edited by gits; Nov 21 '08, 11:08 AM. Reason: added code tags
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    This example may help you.


    [HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator " CONTENT="EditPl us">
    <META NAME="Author" CONTENT="Ramana n">
    <META NAME="Keywords" CONTENT="demo Form">
    <META NAME="Descripti on" CONTENT="Form Submit">
    <script type="text/javascript">
    function doValidate()
    {
    alert("Inside Validate Function");
    return false;
    }
    </script>
    </HEAD>

    <BODY>
    <form action="demoTri al.html" method="post" onsubmit="retur n doValidate()">
    <table align="center">
    <tr><td>User Name </td><td><input type="text" id="myText" name="myText" /></td></tr>
    <tr><td>Passwor d </td><td><input type="text" id="myText1" name="myText1" /></td></tr>
    </table>
    <input type="submit" value="doSubmit ">
    </form>
    </BODY>
    </HTML>[/HTML]

    Instead of using button to submit the form, write a submit input type and trigger the submit function in the form tag. That would do the work what you are looking for.

    Regards
    Ramanan Kalirajan

    Comment

    • donomuch
      New Member
      • Nov 2008
      • 2

      #3
      Ramanan,
      Thank you sir. Got it to work.

      Darrell

      Comment

      Working...