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

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

irt.org | Knowledge Base | JavaScript | Form 6 | Q920 [ previous next ]

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

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>

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.