Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q235 How can I submit a form which has more than one text field by just pressing enter, but how do you make everything work if the user isn't running javascript?

irt.org | Knowledge Base | JavaScript | Form 7.1 | Q235 [ previous next ]

Q235 How can I submit a form which has more than one text field by just pressing enter, but how do you make everything work if the user isn't running javascript?

The following allows the form to function when JavaScript is not enabled. It does require the user to hit the submit button to actually send the form:

<script language="JavaScript"><!--
function submit1() {
    document.passwordForm.passwordField.focus();
    return false;
}

function submit2() {
    document.passwordForm.useridField.value = document.useridForm.useridField.value;
    /* perform any validation here */
    return true;
}
//--></script>

<form name="useridForm" onSubmit="return submit1()">
<p>Userid: <input name="useridField" type="text">

<script language="JavaScript"><!--
document.write('<\/form><form name="passwordForm" onSubmit="return submit2()">')
//--></script>

<input name="useridField" type="hidden">
<p>Password: <input name="passwordField" type="password">

<p><input type="submit">
</form>

The two forms are turned into one by the end of the first form and the beginning of the second form only being output if the browser supports JavaScript.

If JavaScript is disabled then the form functions as normal - but it doesn not submit the form when you press enter.

Feedback on 'Q235 How can I submit a form which has more than one text field by just pressing enter, but how do you make everything work if the user isn't running javascript?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.