Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form validation not working in IE

Status
Not open for further replies.

tyutghf

Technical User
Apr 12, 2008
258
GB
I have some basic form validation, it works fine in all browsers apart from IE. In IE even if the value is selected I get the alert message.

Code:
<script type="text/javascript"> 
function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}
 
function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(quantity,"Please enter a quantity")==false)
  {quantity.focus();return false;}
		
		
		if (validate_required(colour,"Please enter a colour")==false)
  {colour.focus();return false;}
		
		
  }
		
}
</script>

Have I made a basic IE mistake?

Thanks
 
Sorry, lame original post without enough info

Code:
<form action='/basket/default.asp' method='post' onsubmit='return validate_form(this)'>
<input type='hidden' name='itemid' value='42' />
 
Quantity <input type='text' name='quantity' value='1' class='quantityfield' />
 
 
<br /><br />
Colour: <select name='colour'><option value=''>Please select</option><option>Blue</option><option>Green</option></select><br /><br /><input type='submit' name='submit' value='Add to basket' />
 
</form>
 
Your drop down has no actual values. The JS in IE unlike other browsers does not automatically take the text and turn it into a value.
Give your options actual defined values.

Code:
<option [red]value[/red]="blue">Blue</option>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Oh heck, thanks!

The select element was created using asp and a replace string, not sure how to fix this so heading over to asp...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top