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

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.