Jump to content

[SOLVED] simple validation no worky


piznac

Recommended Posts

Not sure but not this script continues to send the form even though I have it to return false,.. very new to js,. any help would be nice:

 

<script language="javascript" type="text/javascript">

function valid(){
if(document.or.cust_name.value == ""){
	alert('Customer name must be filled out.');
	return false;		
}else if(document.or.add1.value == ""){
	alert('Address must be filled out.');
	return false;		
}else if(document.or.state.value == ""){
	alert('State must be filled out.'); 
	return false;
}else if(document.or.city.value == ""){
	alert('City must be filled out.'); 
	return false;
}else if(document.or.zip.value == ""){
	alert('Zipcode must be filled out.'); 
	return false;
}else if(document.or.p_name.value == ""){
	alert('Project name must be filled out.'); 
	return false;
}else if(document.or.date.value == ""){
	alert('Date needed must be filled out.'); 
	return false;
}else{
	return true;
}

}
</script>

 

This is set on an "onsubmit" btw

Link to comment
https://forums.phpfreaks.com/topic/70795-solved-simple-validation-no-worky/
Share on other sites

Are the alerts working  for you? If the alerts are working, but it still subimts the form when its invalid, we need to see the form submission code. I would try something like

 

<script language="javascript" type="text/javascript">

function valid(){
if(document.or.cust_name.value == ""){
	alert('Customer name must be filled out.');
	return false;		
}else if(document.or.add1.value == ""){
	alert('Address must be filled out.');
	return false;		
}else if(document.or.state.value == ""){
	alert('State must be filled out.'); 
	return false;
}else if(document.or.city.value == ""){
	alert('City must be filled out.'); 
	return false;
}else if(document.or.zip.value == ""){
	alert('Zipcode must be filled out.'); 
	return false;
}else if(document.or.p_name.value == ""){
	alert('Project name must be filled out.'); 
	return false;
}else if(document.or.date.value == ""){
	alert('Date needed must be filled out.'); 
	return false;
}else{
	// The form is valid! Let's submit it...
	document.getElementById('myForm').submit();
}

}
</script>

 

So this way, at the bottom of your form, you can have a button like this

<input type='button' value='Submit' onclick='valid()' />

instead of

<input type='submit' value='Submit' />

 

Hope this helps you...

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.