Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a field "REQUIRED"

Status
Not open for further replies.

bkoltys

Programmer
Apr 11, 2001
8
US
Trying to make certain fields "Required" on my "get info" screen in my web page. Example, someone fills out their name, address, city, etc but forgets to put in a ZIP CODE I need a window to pop up that says "Zip is a Required field" or somehting to that effect. This is what I have now.

<TD WIDTH=&quot;37%&quot; VALIGN=&quot;MIDDLE&quot;><INPUT TYPE=&quot;text&quot; NAME=&quot;21zip&quot;></TD>
</TR>
<script language=&quot;JavaScript&quot;>
var response = &quot;21zip&quot;
if(response == &quot; &quot;)
{alert(&quot;Entry Required&quot;)
}
</script>


Any ideas??
 
<script>
function validate(){
if (document.formname.21zip.value=&quot;&quot;) {
alert (&quot;you have to fill all the fields i said !&quot;)
return false
}
return true
}
</script>

and
<form name=formname>
INPUT TYPE=&quot;text&quot; NAME=&quot;21zip&quot;>
</form>
 
yes, and i also forgot this very important call :
<form name=formname onsubmit=&quot;return validate()&quot;>

thank you jared :))

time to go back home, too much work today turned my brain into a ... black hole ....
 
you might want to do it like this so you wont accept a whole bunch of spaces:

if (/^\s*$/.test(document.formname.21zip.value)) { jared@eae.net -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top