7 Replies - 4557 Views - Last Post: 06 April 2006 - 11:32 AM

#1 srossouw   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-March 06

Form Submit button

Posted 03 April 2006 - 02:25 PM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: Form Submit button

#2 supersloth   User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4675
  • View blog
  • Posts: 28,498
  • Joined: 21-March 01

Re: Form Submit button

Posted 03 April 2006 - 02:47 PM

i BELIEVE you can kind of avoid this by removing the action attribute from the formtag and changing your submit button to onclick=submit() with some tricky javascript. i just looked thru some files and couldn't find anything so i may be entirely full of it.


edit- i also believe more than one submit button and any text areas effect how the enter key works within a form.
Was This Post Helpful? 0
  • +
  • -

#3 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Form Submit button

Posted 03 April 2006 - 02:52 PM

You should be able to use the onsubmit property of the form to trigger a javascript function that checks to see if all required fields are filled out, otherwise the form does not submit.
Was This Post Helpful? 0
  • +
  • -

#4 the_hangman   User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: Form Submit button

Posted 03 April 2006 - 03:02 PM

supersloth, on 3 Apr, 2006 - 01:39 PM, said:

i BELIEVE you can kind of avoid this by removing the action attribute from the formtag and changing your submit button to onclick=submit() with some tricky javascript. i just looked thru some files and couldn't find anything so i may be entirely full of it.


edit- i also believe more than one submit button and any text areas effect how the enter key works within a form.

You are right BELIEVE it or not.


I actually just made a page like that. no action in the form is kind of bad code form, so I just replaced the action with null ("#" or "#nogo") which keeps the page from refreshing and removing entered data.
Then I used the onlick function do perform the javascript. You can even have multiple submit buttons doing multiple functions this way. BUUUUUUUT

Here's the catch. The enter button still submits, and it only submits the first submit function (if you have more than one submit). You also have to write a code that actually stops submitting when validating. A lot of the time they just alert you that the required fields are not filled out, but the form still submits.
Was This Post Helpful? 0
  • +
  • -

#5 the_hangman   User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: Form Submit button

Posted 03 April 2006 - 03:09 PM

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



I found this on the internet, so I have no idea if it really works (i'll test it later when I'm not at work). It worked on the page where i found it, and it seems theoretically sound. It captures the numeric key code, and discards any notation of its being pressed. Just paste it in your <head> section.

Only thing is that it completely disables the enter key. it wont work on anything on that page.
Was This Post Helpful? 0
  • +
  • -

#6 srossouw   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-March 06

Re: Form Submit button

Posted 06 April 2006 - 10:20 AM

thanks for the help guys!
Hangman Thanks! that enter disable code does the trick :D
thats all i need it to do.
Was This Post Helpful? 0
  • +
  • -

#7 skyhawk133   User is online

  • Head DIC Head
  • member icon

Reputation: 1962
  • View blog
  • Posts: 20,414
  • Joined: 17-March 01

Re: Form Submit button

Posted 06 April 2006 - 10:32 AM

If you have a button of type button instead of type submit:

<input name="" type="button" />


Instead of

<input name="" type="submit" />


The enter key shouldn't be bound to a button like it is a submit. Then you would do what everyone else suggested and put the onclick="submit()"
Was This Post Helpful? 0
  • +
  • -

#8 the_hangman   User is offline

  • D.I.C Addict
  • member icon

Reputation: 14
  • View blog
  • Posts: 602
  • Joined: 18-January 06

Re: Form Submit button

Posted 06 April 2006 - 11:32 AM

you know what.. your right. that was a lot easier lol
i totally forgot about that.

if you need one submit button to perform 2 functions though, will just a "button" do that? I know I left the submits as "submit" because I also had a background code that had to be performed by the action in the form tag. but i eventually got rid of that and replaced it with the null
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1