Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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?

You are here: irt.org | FAQ | JavaScript | Form | 7.1 | Q235 [ previous next ]

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?'

©2018 Martin Webb