How to make a Select Field required in asp

How to make this field selection REQUIRED please correct my script or add.
<DIV class=item><SPAN class=title><b><font color="red"><b> * </b></font>Industry category : </SPAN>
            <SELECT name="industrycategory" class=f-textName>
        <OPTION value="" selected class=f-textName>Select One</OPTION>
        <OPTION value="Employers" class=f-textName>Employers</OPTION>
        <OPTION value="Business / Employer Associations" class=f-textName>Business / Employer Associations</OPTION>
        <OPTION value="Unions" class=f-textName>Unions</OPTION>
        <OPTION value="Employees / Journeypersons" class=f-textName>Employees/Journeypersons</OPTION>
        <OPTION value="Apprentices" class=f-textName>Apprentices</OPTION>
        <OPTION value="Governments" class=f-textName>Governments</OPTION>
        <OPTION value="Research Organizations" class=f-textName>Research Organizations</OPTION>
        <OPTION value="Sector Councils" class=f-textName>Sector Councils</OPTION>
        <OPTION value="NGOs" class=f-textName>NGOs</OPTION>
        <OPTION value="Students" class=f-textName>Students</OPTION>
        <OPTION value="Parents" class=f-textName>Parents</OPTION>
        <OPTION value="Other" class=f-textName>Other</OPTION></SELECT></DIV>    

<script>
function checkForm(theForm){
  if(theForm.txtCompanyName.value==''){
    alert("You must enter your company name.");
    theForm.txtCompanyName.focus();
    return false;     
  }
  if(!theForm.txtEmail.value.match(/^\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.[a-z]{2,4}$/)){
    alert("You must enter your email address.");
    theForm.txtEmail.select();
    theForm.txtEmail.focus();
    return false;     
  }
  return true;
}
</script>
         
 
 <form style="100%" name="YourFormName" method="Post" action="cf_employer_participation.asp" onSubmit="return checkForm(this);">

Open in new window

elieazziAsked:
Who is Participating?
 
fsze88Connect With a Mentor Commented:
??
validate the value of textarea (purpose) also?
if yes following tested on IE6,FF3
<script>
function checkForm(theForm){
  if(theForm.industrycategory.selectedIndex ==0){
    alert("You must select a option from Industry category.");
    return false;
  }
 
  if (theForm.purpose.value == ""){
    alert("You enter something on textarea");
    return false;
  }
 
  return true;
}
</script>
         
 
 <form style="100%" name="YourFormName" method="Post" action="cf_employer_participation.asp" onSubmit="return checkForm(this);">
 
 <DIV class=item><SPAN class=title><b><font color="red"><b> * </b></font>Industry category : </SPAN>
            <SELECT name="industrycategory" class=f-textName>
        <OPTION value="" selected class=f-textName>Select One</OPTION>
        <OPTION value="Employers" class=f-textName>Employers</OPTION>
        <OPTION value="Business / Employer Associations" class=f-textName>Business / Employer Associations</OPTION>
        <OPTION value="Unions" class=f-textName>Unions</OPTION>
        <OPTION value="Employees / Journeypersons" class=f-textName>Employees/Journeypersons</OPTION>
        <OPTION value="Apprentices" class=f-textName>Apprentices</OPTION>
        <OPTION value="Governments" class=f-textName>Governments</OPTION>
        <OPTION value="Research Organizations" class=f-textName>Research Organizations</OPTION>
        <OPTION value="Sector Councils" class=f-textName>Sector Councils</OPTION>
        <OPTION value="NGOs" class=f-textName>NGOs</OPTION>
        <OPTION value="Students" class=f-textName>Students</OPTION>
        <OPTION value="Parents" class=f-textName>Parents</OPTION>
        <OPTION value="Other" class=f-textName>Other</OPTION></SELECT></DIV>
        
        <input type="submit" value="try submit"> 
        <textarea name="purpose" rows="4" cols="35"></textarea>
        </form>

Open in new window

0
 
fsze88Commented:
tested on IE6,FF3
<script>
function checkForm(theForm){
/*
  if(theForm.txtCompanyName.value==''){
    alert("You must enter your company name.");
    theForm.txtCompanyName.focus();
    return false;     
  }
  if(!theForm.txtEmail.value.match(/^\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.[a-z]{2,4}$/)){
    alert("You must enter your email address.");
    theForm.txtEmail.select();
    theForm.txtEmail.focus();
    return false;     
  }
  */
//  alert(theForm.industrycategory.selectedIndex);
  if(theForm.industrycategory.selectedIndex ==0){
    alert("You must select a option from Industry category.");
    return false;
  }
  return true;
}
</script>
         
 
 <form style="100%" name="YourFormName" method="Post" action="cf_employer_participation.asp" onSubmit="return checkForm(this);">
 
 <DIV class=item><SPAN class=title><b><font color="red"><b> * </b></font>Industry category : </SPAN>
            <SELECT name="industrycategory" class=f-textName>
        <OPTION value="" selected class=f-textName>Select One</OPTION>
        <OPTION value="Employers" class=f-textName>Employers</OPTION>
        <OPTION value="Business / Employer Associations" class=f-textName>Business / Employer Associations</OPTION>
        <OPTION value="Unions" class=f-textName>Unions</OPTION>
        <OPTION value="Employees / Journeypersons" class=f-textName>Employees/Journeypersons</OPTION>
        <OPTION value="Apprentices" class=f-textName>Apprentices</OPTION>
        <OPTION value="Governments" class=f-textName>Governments</OPTION>
        <OPTION value="Research Organizations" class=f-textName>Research Organizations</OPTION>
        <OPTION value="Sector Councils" class=f-textName>Sector Councils</OPTION>
        <OPTION value="NGOs" class=f-textName>NGOs</OPTION>
        <OPTION value="Students" class=f-textName>Students</OPTION>
        <OPTION value="Parents" class=f-textName>Parents</OPTION>
        <OPTION value="Other" class=f-textName>Other</OPTION></SELECT></DIV>
        
        <input type="submit" value="try submit"> 
        </form>

Open in new window

0
 
elieazziAuthor Commented:
thank you but how i'm able to do it for a textarea too and i'm done.

<DIV class="item last"><SPAN class=title><b><font color="red"><b> * </b></font>Purpose</b><font size="-2"><br>(Please briefly outline your outreach efforts for our office to track the distribution of this material)</font></font></SPAN><br>

<textarea name="purpose" rows="4" cols="35"></textarea></DIV>
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
elieazziAuthor Commented:
I did this :

 if(theForm.purpose.value==''){
    alert("Please briefly outline your outreach efforts for our office to track the distribution of this material");
    theForm.purpose.value.focus();
    return false;    
  }

and this change..

 <DIV class="item last"><SPAN class=title><b><font color="red"><b> * </b></font>Purpose</b><font size="-2"><br>(Please briefly outline your outreach efforts for our office to track the distribution of this material)</font></font></SPAN><br><textarea name="purpose" rows="4" cols="35"></textarea></DIV>  

It didn't work any advice please ?
0
 
elieazziAuthor Commented:
Thank you very much, I will have another question report to this one now.
0
 
elieazziAuthor Commented:
Excellent !!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.