how to javascript validateForm

Hello, i have a small form with with about 3 options, i have done the rest of the coding to validate the other fields but am not sure how to validate the other option forms..

here is the form
          <form action="signUp-form.php" method="post" onSubmit="MM_validateForm('Name','','R','Company','','R','Email','','RisEmail');return document.MM_returnValue">
            <table width="315">
              <tr>
                <td width="66" height="30" ><p>Name*: </p></td>
                <td width="666" height="30"><input name="Name" type="text" id="Name" size="25" /></td>
              </tr>
              <tr>
                <td height="30"><p>Company*: </p></td>
                <td height="30"><input name="Company" type="Text" id="Company" size="25" /></td>
              </tr>
              <tr>
                <td height="30"><p>Email*: </p></td>
                <td height="30"><input name="Email" type="Text" id="Email" size="25" /></td>
              </tr>
              <tr>
                <td height="30"><p>Platform*: </p></td>
                <td height="30"><label>
                    <select name="Platform" id="Platform">
                      <option selected>Select a Platform</option>
                      <option>PC</option>
                      <option>Mac</option>
                      <option>Server</option>
                    </select>
                  </label></td>
              </tr>
              <tr>
                <td height="30">&nbsp;</td>
                <td height="30"><input type="submit">
                  </input></td>
              </tr>
            </table>
          </form>

Open in new window



want i want to do is make sure that one of the option is selected...

<option selected>Select a Platform</option>
                      <option>PC</option>
                      <option>Mac</option>
                      <option>Server</option>

Open in new window


here is the function code

<!--form Validator-->
<script type="text/javascript">
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
</script>

Open in new window

businessesatozAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nap0leonCommented:
IMO, change:
                    <select name="Platform" id="Platform">
                      <option selected>Select a Platform</option>
                      <option>PC</option>
                      <option>Mac</option>
                      <option>Server</option>
                    </select>

Open in new window


to

                    <select name="Platform" id="Platform">
                      <option selected value="">Select a Platform</option>
                      <option value="PC">PC</option>
                      <option value="Mac">Mac</option>
                      <option value="Server">Server</option>
                    </select>

Open in new window


then add a test such as
if (document.getElementById("Platform").value==""){
  //add error message here
  errors += '- Platform is required.\n'
} else{
  //they selected a platform, no error
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
businessesatozAuthor Commented:
where should i add the test?

<!--form Validator-->
<script type="text/javascript">
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }
</script>

Open in new window


within this file... also
<form action="signUp-form.php" name="s" method="post" onSubmit="MM_validateForm('Name','','R','Company','','R','Email','','RisEmail');return document.MM_returnValue">

Open in new window

don't i need to change something here?
businessesatozAuthor Commented:
nevermind.. thanks i got it to work..
businessesatozAuthor Commented:
thank you for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.