Jump to content

onSubmit, how to combobox validate?


plodos

Recommended Posts

<script LANGUAGE="JavaScript">
<!--
function ValidateForm(form){
ErrorText= "";
if ( form.age.selectedIndex == 0 ) 
{ 
alert ( "Please select your Age." ); return false; 
}
if (ErrorText= "") 
{ 
form.submit() }
}
-->
</script>

<form name="feedback" action="mailto:[email protected]" method=post   onSubmit="ValidateForm(this.form)">
Your Age: <select name="age"> 
<option value="">Please Select an Option:</option> 
<option value="0-18 years">0-18 years</option> 
<option value="18-30 years">18-30 years</option> 
<option value="60+ years">60+ years</option> 
</select>
<input type="button" name="SubmitButton" value="Submit">
<input type="reset" value="Reset">
</form>

I want to validate the combobox is selected or not...but onSubmit is not working :S

I have already onclick evet I dont know how to combine two onclick event in one function:S

 

What can be the errors..I couldnt find it :s

Link to comment
https://forums.phpfreaks.com/topic/111925-onsubmit-how-to-combobox-validate/
Share on other sites

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<script type="text/JavaScript">
<!--
function ValidateForm(form){

  var ErrorText;

  if ( form.elements['age'].selectedIndex == 0 ) 
  { 
    ErrorText = "Please select your Age.";
  }

  if (ErrorText) 
  {
    alert(ErrorText);
    return false;
  }

  return true;
}
-->
</script>

</script>
</head>

<body>

<form name="feedback" action="" method="post" onSubmit="return ValidateForm(this);">
  Your Age:
  <select name="age"> 
    <option value="">Please Select an Option:</option> 
    <option value="0-18 years">0-18 years</option> 
    <option value="18-30 years">18-30 years</option> 
    <option value="60+ years">60+ years</option> 
  </select>
  <input type="submit" name="SubmitButton" value="Submit">
  <input type="reset" value="Reset">
</form>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.