| | |
Disable "Enter" in radio button area in web form
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
I have a web form. I want the "enter" key disabled from sending the form so users have to SUBMIT in order to send form.
Have the following entered in the head:
It works great in the "text" form area which is in a table format. Sample:
When I get to the radio button area it doesn't work. It is NOT in a table format. Here's a sample of the radio button area:
Any help would be greatly appreciated.
Have the following entered in the head:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function stopRKey(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if ((evt.keyCode == 13) && (node.type=="text")) {return false;} } document.onkeypress = stopRKey;
It works great in the "text" form area which is in a table format. Sample:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<TR> <TD align=right width=40%><FONT size=2><B>First Name: </b></FONT></TD> <TD ><INPUT name=A-firstname></TD></tr> <TR> <TD align=right width=40%><FONT size=2><B>Last Name: </b></FONT></TD> <TD><INPUT name=B-lastname></TD></TR>
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<p> 1. The fundamental building blocks of matter are atoms and _________.<BR> <INPUT type=radio value="a" name="1"> a. mass <BR> <INPUT type=radio value="b" name="1"> b. protons <BR> <INPUT type=radio value="c" name="1"> c. molecules <BR> <INPUT type=radio value="d" name="1"> d. neutrons </p>
0
#2 Oct 17th, 2009
Perhaps try something like this?:
EDIT 1: Also keep in mind that the usage of caps is depercated in XHTML.
EDIT 2: I also don't get the question. Atoms are build out of neutrons, elektrons and protons. Molecules are build out of atoms. And mass is just a wrong answer. Isn't the question wrong?
~G
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
... ...Header HTML ... <script type="text/javascript"> function entersubmit(event) { if (window.event && window.event.keyCode == 13) { return false; } else { if (event && event.which == 13) { return false; } else { return false; } } } </script> <form> <p> 1. The fundamental building blocks of matter are atoms and _________.<BR> <input type=radio value="a" name="1" onkeypress="entersubmit(event)"> a. mass <BR> <input type=radio value="b" name="1" onkeypress="entersubmit(event)"> b. protons <BR> <input type=radio value="c" name="1" onkeypress="entersubmit(event)"> c. molecules <BR> <input type=radio value="d" name="1" onkeypress="entersubmit(event)"> d. neutrons </p> </form> ... ...Footer HTML ...
EDIT 1: Also keep in mind that the usage of caps is depercated in XHTML.
EDIT 2: I also don't get the question. Atoms are build out of neutrons, elektrons and protons. Molecules are build out of atoms. And mass is just a wrong answer. Isn't the question wrong?
~G
Last edited by Graphix; Oct 17th, 2009 at 12:15 pm.
0
#3 Oct 17th, 2009
Serendipity,
The easiest way, in my experience, is not to use a submit button.
Instead, use a regular
Thus, the only way to submit the form should be for the user to click the "Submit" button (or to hit enter if/when it has focus).
I used to be sure that this technique was universally true, but you should test the latest crop of browsers to make sure. I could be out of date.
The slight downside is that
Here is a demo which you can use to do some testing:
Airshow
The easiest way, in my experience, is not to use a submit button.
Instead, use a regular
<input type="button" value="Submit" onclick"this.form.submit();"> . The script gives the necessary submit action.Thus, the only way to submit the form should be for the user to click the "Submit" button (or to hit enter if/when it has focus).
I used to be sure that this technique was universally true, but you should test the latest crop of browsers to make sure. I could be out of date.
The slight downside is that
<form ...... onsubmit="....."> (should you need it) will now not intercept the submission, but the workaround is also simple; modify the "Submit" button's onclick"this.form.submit();" to make submission conditional or whatever you would otherwise put in the form's onsubmit . If it gets complex, then write/call a function.Here is a demo which you can use to do some testing:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Airshow :: Untitled</title> <style type="text/css"> form { margin-top:20px; padding:12px; width:150px ; border:1px solid #999; } </style> <script> function writeInputText(){ document.f1.i1.value = 'ABCDEF'; document.f2.i1.value = 'ABCDEF'; } onload = function(){ setTimeout("writeInputText()", 1000); } </script> </head> <body> <form name="f1" action=""> <input name="i1" value="------"><br> <input><br> <input type="radio" name="x" value="1"><br> <input type="radio" name="x" value="2"><br> <input type="radio" name="x" value="3"><br> <input type="button" value="My Submit" onclick="this.form.submit();"><br> </form> <form name="f2" action=""> <input name="i1" value="------"><br> <input><br> <input type="radio" name="x" value="1"><br> <input type="radio" name="x" value="2"><br> <input type="radio" name="x" value="3"><br> <input type="Submit" value="HTML Submit"><br> </form> </body> </html>
Airshow
Last edited by Airshow; Oct 17th, 2009 at 1:14 pm.
50% of the solution lies in accurately describing the problem!
0
#4 Oct 18th, 2009
Thanks Graphix & Airshow!Graphix, the "fundamental building blocks of matter" are atoms and molecules. You are right, atoms are made of protons, neutrons, electrons, and matter has mass, but is not made up of mass. Matter is also not made up of just protons, neutrons, or electrons. It is made up of atoms and molecules, and yes, molecules are made up of atoms! Hey, that's the point of multiple choice questions, isn't it? -- tricky tricky tricky!!!
![]() |
Similar Threads
- Different action in different radio button ?? (JavaScript / DHTML / AJAX)
- Data binding to a Radio Button (C#)
- Radio button checked? (PHP)
- Validating radio button selection for login redirect (JavaScript / DHTML / AJAX)
- Radio Button and List (JSP)
- need help how to add multiple email addresses on a radio button (ASP)
- Help with some email form features (HTML and CSS)
- How to code "tab control' in the web form in ASP.NET / VB.NET ? (ASP.NET)
- Am not able to get a radio button selection to display in output (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Own html editor
- Next Thread: Best Way to Learn?
Views: 702 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxcode ajaxexample ajaxhelp animate array automatically autoplay beta boarder box captcha card cart codes column css date debugger decimal design developer dom download element embed enter error events firefox flash focus form frameworks getselection google gwt hint html htmlform ie7 iframe image() index java javascript javascripthelp2020 javascripts jawascriptruntimeerror jquery jsp listbox maps marquee masterpage menu microsoft mimic mp4 offline onmouseover parameters paypal php player position post problem programming prototype rating redirect regex safari scale scriptlets search select size sources sql starrating text textarea toggle tweet twitter validation variables w3c web webkit webservice website window windowofwords windowsxp xml xspf





