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:aaa@aaa.com" 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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.