SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ENTER triggers Submit Button, how to disable?

    Hi guys
    i have idiots filling in my form, instead of TAB button to move to next text field, they hit ENTER which triggers the Submit Button. so they submit half empty forms. Is there a way to disable this so they MUST click the button? any help appreciated.

  2. #2
    Ding Fries are Done! inter4design's Avatar
    Join Date
    Mar 2003
    Location
    usa
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    an easier thing to do is maybe disable the submit button untill all the fields that are required are filled out.
    DoesItMatter
    - anyone seen my underwear?

  3. #3
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mmmm.... suppose i would have to know how to code that right? any ideas wher to find this code? i now feel like the idiot

  4. #4
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Moved this to the JavaScript forum as that is mostly likely what you'll need for this.

  5. #5
    I ♥ PHP
    Join Date
    Jul 2003
    Location
    Melbourne, Australia
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the code for your form please? It should be pretty easy to implement this.


    Regars,
    Jordan

  6. #6
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <form method="post" action="http://www.xxxxxxxxxx.com/forxxx.php" name="xxForm">
    <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER">

    <input type="hidden" name="recipients" value="" /> ((goes to csv file))

    <input type="hidden" name="required" value="email:Your Email address, surname:Your name, smartcard:Your Smart Card Number" />

    <input type="hidden" name="subject" value="Data from Form " />
    <input type="hidden" name="csvfile" value="data.csv" />
    <input type="hidden" name="csvcolumns" value="surname, firstname, email, member, SAICAnumber, cell, smartcard, fax, postal1, postal2, city, postcode, homeTel, IDnumber" />
    <input type="hidden" name="good_url" value="http://xxxxxxx.com/xxxxxxe.htm" />
    <table width="500" border="1" align="center" cellspacing="5%">
    <tr>
    <td width="187" valign="top"><p>Surname/p></td>
    <td width="145"><input name="surname" type="text" id="surname" />
    </td>
    </tr>
    <tr>
    <td valign="top"><p>First (Given) Names/p></td>
    <td><input name="firstname" type="text" id="firstname" />
    etc etc etc etc.
    <input type="submit" value="Submit" />
    THANKS for help!

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    <form method="post" action="http://www.xxxxxxxxxx.com/forxxx.php" name="xxForm" onsubmit="return validate(this)">

    and then just finish coding the following Javascript to perform the necessary validations):

    Code:
    function validate(f) {
    var req = f.required.value.split(',');
    for (var i=0; i<req.length; i++) {
    // code to test if the specified field has something in it goes here, if it doesn't then return false
    }
    return true;
    }
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Steven and other guys

    re: // code to test if the specified field......

    unfortunately I dont know much Jscript
    if u have the time, u maybe have example of this code?
    thanks man

  9. #9
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys
    got this from somewhere else
    it disables the Enter key press on the form:

    function kH(e) {
    var pK = e ? e.which : window.event.keyCode;
    return pK != 13;
    }
    document.onkeypress = kH;
    if (document.layers) document.captureEvents(Event.KEYPRESS);

    it works..


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
  •