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

Q360 Is it possible to validate both a pull down menu and a text area when a form is submitted?

irt.org | Knowledge Base | JavaScript | Form 3.4 | Q360 [ previous next ]

Q360 Is it possible to validate both a pull down menu and a text area when a form is submitted?

Yes, although there is always one item in a pulldown menu that is always selected, therefore make the first entry a comment type entry:

<SCRIPT LANGUAGE="JavaScript"><!--
function validate() {
    var valid = true, output = '';

    if (document.myForm.mySelect.selectedIndex == 0) {
        valid = false;
        output = 'Select an entry from the pulldown menu\n';
    }

    if (document.myForm.myText.value.length == 0) {
        valid = false;
        output += 'Enter some text in the text area';
    }

    if (!valid)
        alert(output);

    return valid;
}
//--></SCRIPT>

<FORM NAME="myForm" onSubmit="return validate()">
<SELECT NAME="mySelect">
<OPTION VALUE="">Pick one:
<OPTION VALUE="1">First
<OPTION VALUE="2">Second
<OPTION VALUE="3">Third
</SELECT>
<TEXTAREA NAME="myText"></TEXTAREA>
<INPUT TYPE="SUBMIT">

Feedback on 'Q360 Is it possible to validate both a pull down menu and a text area when a form is submitted?'


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.