[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to make a Select Field required in asp

Posted on 2009-02-13
6
Medium Priority
?
238 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:elieazzi
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:fsze88
ID: 23634821
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
 

Author Comment

by:elieazzi
ID: 23635009
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
 

Author Comment

by:elieazzi
ID: 23635221
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 15

Accepted Solution

by:
fsze88 earned 2000 total points
ID: 23635269
??
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
 

Author Comment

by:elieazzi
ID: 23635525
Thank you very much, I will have another question report to this one now.
0
 

Author Closing Comment

by:elieazzi
ID: 31546682
Excellent !!!!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question