Jump to content

Recommended Posts

I'm very new to Java script and I've created a form with check boxes and a dropdown menu.  I want to validate both on submit.  I got it to work, but can't get them to work TOGETHER... I know I'm going about this wrong.. please help if possible... here's what I have:

 

<script type="text/javascript">
function validate(form) {

if(!document.form1.agree.checked){alert("Please check the terms and conditions");
return false; }

return true;
}
</script>

<form name="form1" method="post" action="sendorderform.php" onsubmit="return validate(this)">

 

AND

 

<SCRIPT LANGUAGE="JavaScript"'>
<!--
function validateForm(){
if(document.form1.emailto.selectedIndex==0)
{
alert("Please select an Item.");
document.form1.emailto.focus();
return false;
}
return true;
}
//-->
</SCRIPT> 

<form name="form1" method="post" action="sendorderform.php" onsubmit="return validateForm()">

 

Both of these, when put on the page alone, work great.  But I don't know how to get them to work together.  I need onsubmit to validate both things...  Google isn't helping very much.  Any help would be great!!!  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/233427-probably-simple-simple-simple/
Share on other sites

I figured it out... at least one way to do it...

 

<script type="text/javascript">
function validate(form) {

if(!document.form1.agree.checked){alert("Please check the terms and conditions");
return false; }


if(document.form1.emailto.selectedIndex==0)
{
alert("Please select a store location");
document.form1.emailto.focus();
return false;
}
return true;
}
//-->
</SCRIPT> 

<form name="form1" method="post" action="sendorderform.php" onsubmit="return validate(this)">

 

Thanks to anyone who might have been thinking about helping me.  I'm all set now.

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.