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

Q920 How can I populate a form field if it is empty when the form is submitted?

You are here: irt.org | FAQ | JavaScript | Form | 6 | Q920 [ previous next ]

Try:

<script language="JavaScript"><!--
function defaultField(what,text) {
    if (what.value == '')
        what.value = text;
}
//--></script>

<form onSubmit="defaultField(this.form.tel,'No phone')">
<input type="text" name="tel">
</form>

©2018 Martin Webb