Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Validation = Trap Door?

    Hello all...
    my sub title might be a bit confusing, but here's what's happening. With some kind help here from others in the past 2 weeks, I now have a great ASP form that uses javascipt to validate user entries, including radioButtons (thanks Kor!)

    But I guess what I never thought of, or even explained to any here was, that this ASP form, when completed & validated, goes to a page that emails the various form fields.

    My validation works perfectly, prompting me to not miss an item on the form on my dev box (where I do not have CDONTS installed). But when uploaded just now to my test server, I tested the complete version by failing to fill in the first field -- was properly cautionned by the javascript that I'd not filled it in -- then whized by the email page to the final page that thanks the user for filling in the form.

    Just like a "trap door" it suddenly accepts the form without going back to allow a user to fill in the missing field, or fields????

    That is, the javascript, while supposed to STOP the form from completing, instead shows the Alert, then goes to the email page.

    Is there a way to NOT have that happen, ie to ensure that the complete form is COMPLETED, before it moves off to the next page?

    ???

    Jim

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Without seeing your code it's hard to answer, but when I want to validate a form before submitting I do something like this.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    	function formValid()
    	{
    		var stat=0;
    		for(var i=0;i<document.forms[0].length;i++)
    		{
    			var obj=document.forms[0].elements[i]
    			if(obj.value=="")
    			{
    				stat=1;
    			}
    		}
    		if(stat==1)
    		{
    			alert("Fill it all out")
    		}
    		else
    		{
    			document.forms[0].submit();
    		}
    	}
    </script>
    </head>
    <body>
    <form onsubmit="formValid();return false;">
    	<input type="text">
    	<input type="submit">
    </form>
    The important thing here being the return false after calling the validation function in the onsubmit event handler.

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ahh....I see

    something in your <form> syntax that I don't have...

    While its LONG, I've put the snipped it and put some page code here for you to look at...what do I need to put in my own <form> tag to prevent the form from going "on" when fields are still empty?

    Code:
    <!--------------------------------------------------------------->
    <!-- FORM HERE TO GO TO sendorder.ASP-------------------------------->
    <form name="outputForm" method="post" action="sendOrderSingle.asp">
    <!---------------------------------------------------------------------->
    
    
    <!-- WELCOME CONTENTS HERE ---------------------------------------->
    <DIV style="position:absolute;left:25;top:180;width:850;height:420;z-index:14;visibility:visible;">
    <br>
    
    
    <table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">
    <tr><td>
    
    <table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#cccccc">
    <tr><td>
    
    <center>
    <b><font size="4" face="Verdana">TERMS</font></b>
    </center><img src="images/SPACER.GIF" width="70" height="70" border="0" align="left">
    
    <font size="2" face="Verdana" color="black">• Payment terms are net 15 days from date of delivery<br>
    <font size="2" face="Verdana" color="black">• All first time shipments must be pre-paid<br>
    <font size="2" face="Verdana" color="black">• Credit Approval and account set-up takes 72 hours<br>
    <font size="2" face="Verdana" color="black">• We accept Visa & MasterCard<br>
    <font size="2" face="Verdana" color="black">• <b>1 - 866 - DRV - STAR</b><br>
    <br>
    
    <font size="2" face="Verdana" color="red">
    <center>
    <b>Note - all fields must be completely filled in so that we can process your order!</b>
    </center>
    </td></tr>
    </table>
    </table>
    
    <!-- CUSTOMER INFO------------------------------------->
    <!-- HEADERS -->
    <table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#CCCCCC">
    <tr>
    <td>
    
    <table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#a1a1a1">
    <tr bgcolor="#a1a1a1">
    <td>
    
    <tr bgcolor=#183DA8>
    <td colspan=3><font size="3" face="Verdana" color="white"><b>&nbsp;&nbsp;Please Indicate if this is an Order or a Request for a Quote :
    ORDER : <input type="radio" name="radioQuote" value="Order">&nbsp;&nbsp;&nbsp;&nbsp;
    QUOTE : <input type="radio" name="radioQuote" value="Quote">
    <br>
    </td>
    </tr>
    
    
    <tr bgcolor=#183DA8>
    <td colspan=3><font size="3" face="Verdana" color="white"><b>&nbsp;&nbsp;Customer Information :
    </td>
    </tr>
    <tr>
    	<td><font size="2" face="Verdana" color="black"><b>Company Name :</b><br> <input type="text" name="txtCoName" size="30"></td>
    	<td><font size="2" face="Verdana" color="black"><b>Address :</b> <br><input type="text" name="txtCoAddress" size="30"></td>
    	<td><font size="2" face="Verdana" color="black"><b>City : </b><br><input type="text" name="txtCoCity" size="20"></td>
    </tr>
    <tr>
    	<td>
    	<font size="2" face="Verdana" color="black"> <b>State or Province...</b>
    	</td>
    
    
    			<td nowrap colspan=2>
    			<SELECT size=1 name="CoState">
                  <OPTION selected>Choose a Province or State...
    			   <option value="Alberta">Alberta</option>
                  <option value="British Columbia">British Columbia</option>
                  <option value="Manitoba">Manitoba</option>
                  <option value="New Brunswick">New Brunswick</option>
                  <option value="Newfoundland">Newfoundland</option>
                  <option value="North West Terrorties">North West Terrorties</option>
                  <option value="Nova Scotia">Nova Scotia</option>
                  <option value="Ontario">Ontario</option>
                  <option value="Prince Edward Island">Prince Edward Island</option>
                  <option value="Quebec">Quebec</option>
                  <option value="Saskatchewan">Saskatchewan</option>
    
                 
                </SELECT>
    	</td>
    </tr>
    <tr>
    	<td><font size="2" face="Verdana" color="black"><b>Zip/Postal Code :</b> <br><input type="text" name="txtCoZip" size="12"></td>
    	<td><font size="2" face="Verdana" color="black"><b>Contact Name : </b><br><input type="text" name="txtCoContactName" size="30"></td>
    	<td><font size="2" face="Verdana" color="black"><b>Phone # : </b><br><input type="text" name="txtCoPhone" size="20"></td>
    </tr>
    
    <tr>
    	<td><font size="2" face="Verdana" color="black"><b>Fax :</b> <br><input type="text" name="txtCoFax" size="12"></td>
    	<td><font size="2" face="Verdana" color="black"><b>Email :</b> <br><input type="text" name="txtCoEmail" size="30"></td>
    	<td><font size="2" face="Verdana" color="black"><b>Purchase Order # :</b> <br><input type="text" name="txtPONum" size="30"></td>
    </tr>
    </td>
    </tr>
    
    <tr>
    <td NOWRAP valign="middle"><font size="2" face="Verdana" color="black"><b>Please Indicate Which Service Level You Require &nbsp;&nbsp;</b><br>
    <font size="1" face="Verdana" color="black">
    	<a href="services.asp" target="_blank"> Click here to review Service Levels....</a>
    </td>
    
    <td colspan=2><font size="2" face="Verdana" color="black">&nbsp;&nbsp;&nbsp;
    	<b>Level A : </b><input type="radio" name="radioServiceLevel"  value="A">
    		
    	<b>Level B : </b><input type="radio" name="radioServiceLevel"  value="B">
    
    	<b>Level C : </b><input type="radio" name="radioServiceLevel"  value="C">
    </td>
    </tr>
    
    <tr>
    <td><font size="1" face="Verdana" color="white"><b>
    To send us your Order or Request a Quote, please click the SEND button...</b>
    </td>
    	
    <td>input type="submit" value="SEND" name="SUBMIT" onClick="validate(outputForm)">
    
    <input type="reset">
    
    </td>
    </tr>
    </table>
    </td></tr>
    <table>
    </body>
    </html>
    Hopefully, it's something as simple as that....

    ?

    Jim

  • #4
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Try this, not sure because I can't see the JS.

    Code:
    <!--------------------------------------------------------------->
    <!-- FORM HERE TO GO TO sendorder.ASP-------------------------------->
    <form name="outputForm" onsubmit="validate(this.name);return false;" method="post" action="sendOrderSingle.asp">
    <!---------------------------------------------------------------------->
    
    
    <!-- WELCOME CONTENTS HERE ---------------------------------------->
    <DIV style="position:absolute;left:25;top:180;width:850;height  :420;z-index:14;visibility:visible;">
    <br>
    
    
    <table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">
    <tr><td>
    
    <table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#cccccc">
    <tr><td>
    
    <center>
    <b><font size="4" face="Verdana">TERMS</font></b>
    </center><img src="images/SPACER.GIF" width="70" height="70" border="0" align="left">
    
    <font size="2" face="Verdana" color="black">• Payment terms are net 15 days from date of delivery<br>
    <font size="2" face="Verdana" color="black">• All first time shipments must be pre-paid<br>
    <font size="2" face="Verdana" color="black">• Credit Approval and account set-up takes 72 hours<br>
    <font size="2" face="Verdana" color="black">• We accept Visa & MasterCard<br>
    <font size="2" face="Verdana" color="black">• <b>1 - 866 - DRV - STAR</b><br>
    <br>
    
    <font size="2" face="Verdana" color="red">
    <center>
    <b>Note - all fields must be completely filled in so that we can process your order!</b>
    </center>
    </td></tr>
    </table>
    </table>
    
    <!-- CUSTOMER INFO------------------------------------->
    <!-- HEADERS -->
    <table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#CCCCCC">
    <tr>
    <td>
    
    <table cellspacing="0" border="1" cellpadding="0" width="100%" bordercolorlight="#808080" bordercolordark="#FFFFFF" bgcolor="#a1a1a1">
    <tr bgcolor="#a1a1a1">
    <td>
    
    <tr bgcolor=#183DA8>
    <td colspan=3><font size="3" face="Verdana" color="white"><b>&nbsp;&nbsp;Please Indicate if this is an Order or a Request for a Quote :
    ORDER : <input type="radio" name="radioQuote" value="Order">&nbsp;&nbsp;&nbsp;&nbsp;
    QUOTE : <input type="radio" name="radioQuote" value="Quote">
    <br>
    </td>
    </tr>
    
    
    <tr bgcolor=#183DA8>
    <td colspan=3><font size="3" face="Verdana" color="white"><b>&nbsp;&nbsp;Customer Information :
    </td>
    </tr>
    <tr>
    	<td><font size="2" face="Verdana" color="black"><b>Company Name :</b><br> <input type="text" name="txtCoName" size="30"></td>
    	<td><font size="2" face="Verdana" color="black"><b>Address :</b> <br><input type="text" name="txtCoAddress" size="30"></td>
    	<td><font size="2" face="Verdana" color="black"><b>City : </b><br><input type="text" name="txtCoCity" size="20"></td>
    </tr>
    <tr>
    	<td>
    	<font size="2" face="Verdana" color="black"> <b>State or Province...</b>
    	</td>
    
    
    			<td nowrap colspan=2>
    			<SELECT size=1 name="CoState">
                  <OPTION selected>Choose a Province or State...
    			   <option value="Alberta">Alberta</option>
                  <option value="British Columbia">British Columbia</option>
                  <option value="Manitoba">Manitoba</option>
                  <option value="New Brunswick">New Brunswick</option>
                  <option value="Newfoundland">Newfoundland</option>
                  <option value="North West Terrorties">North West Terrorties</option>
                  <option value="Nova Scotia">Nova Scotia</option>
                  <option value="Ontario">Ontario</option>
                  <option value="Prince Edward Island">Prince Edward Island</option>
                  <option value="Quebec">Quebec</option>
                  <option value="Saskatchewan">Saskatchewan</option>
    
                 
                </SELECT>
    	</td>
    </tr>
    <tr>
    	<td><font size="2" face="Verdana" color="black"><b>Zip/Postal Code :</b> <br><input type="text" name="txtCoZip" size="12"></td>
    	<td><font size="2" face="Verdana" color="black"><b>Contact Name : </b><br><input type="text" name="txtCoContactName" size="30"></td>
    	<td><font size="2" face="Verdana" color="black"><b>Phone # : </b><br><input type="text" name="txtCoPhone" size="20"></td>
    </tr>
    
    <tr>
    	<td><font size="2" face="Verdana" color="black"><b>Fax :</b> <br><input type="text" name="txtCoFax" size="12"></td>
    	<td><font size="2" face="Verdana" color="black"><b>Email :</b> <br><input type="text" name="txtCoEmail" size="30"></td>
    	<td><font size="2" face="Verdana" color="black"><b>Purchase Order # :</b> <br><input type="text" name="txtPONum" size="30"></td>
    </tr>
    </td>
    </tr>
    
    <tr>
    <td NOWRAP valign="middle"><font size="2" face="Verdana" color="black"><b>Please Indicate Which Service Level You Require &nbsp;&nbsp;</b><br>
    <font size="1" face="Verdana" color="black">
    	<a href="services.asp" target="_blank"> Click here to review Service Levels....</a>
    </td>
    
    <td colspan=2><font size="2" face="Verdana" color="black">&nbsp;&nbsp;&nbsp;
    	<b>Level A : </b><input type="radio" name="radioServiceLevel"  value="A">
    		
    	<b>Level B : </b><input type="radio" name="radioServiceLevel"  value="B">
    
    	<b>Level C : </b><input type="radio" name="radioServiceLevel"  value="C">
    </td>
    </tr>
    
    <tr>
    <td><font size="1" face="Verdana" color="white"><b>
    To send us your Order or Request a Quote, please click the SEND button...</b>
    </td>
    	
    <td><input type="submit" value="SEND" name="SUBMIT">
    
    <input type="reset">
    
    </td>
    </tr>
    </table>
    </td></tr>
    <table>
    </body>
    </html>
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trap door still working...heres' the javascript

    Still, falls right thru....ie the change to this line in the form...

    <form name="outputForm" onsubmit="validate(this.name);return false;" method="post" action="sendOrderSingle.asp">

    -- made no difference....

    trap door still works -- dang it!


    Code:
    <!-- FORM VALIDATION ------------------------------------------------------------------------------------------------------------------------------>
    <!-- --------------------------------------------------------------------------------------------------------------------------------------------------------- -->
    
    <!-- called by ordrerSingle.asp for use to validate ALL items...... -->
    
     <script LANGUAGE="JavaScript">
    	<!-- HIDE FROM OTHER BROWSERS
    
    	function validate(outputForm) 
    	{
    
    // Customer Here....missing radio button validates??
    //---------------------------------------------------------------------------------------------------------------
    
    // Order or quote here
    
    
    // for Order or Quote radioButtons
    		var r = document.forms[0].elements['radioQuote'];//the radio buttons as a collection 
    		var param = 0; 
    		for(var i=0;i<r.length;i++){ 
    		
    		if (r[i].checked){param++} 
    			} 
    				if(param==0){ 
    						alert("Please choose either Order or Quote. Thank you."); 
    				return false}  
    
    
    		if (outputForm.txtCoName.value == "")
      			{
    			alert("The Company Name is required. Thank you.");
    			outputForm.txtCoName.focus();
    			return (false);
      			}
    
    		if (outputForm.txtCoAddress.value == "")
      			{
    			alert("The Company Address is required. Thank you.");
    			outputForm.txtCoAddress.focus();
    			return (false);
      			}
    
    		if (outputForm.txtCoCity.value == "")
      			{
    			alert("The Company Head Office City is required. Thank you.");
    			outputForm.txtCoCity.focus();
    			return (false);
      			}
    
    
    		if (outputForm.CoState.value == "")
      			{
    			alert("The Company State or Province is required. Thank you.");
    			outputForm.CoState.focus();
    			return (false);
      			}
    
    
    		if (outputForm.txtCoZip.value == "")
      			{
    			alert("The Company Zip or Postal Code is required. Thank you.");
    			outputForm.txtCoZip.focus();
    			return (false);
      			}
    
    		if (outputForm.txtCoContactName.value == "")
      			{
    			alert("The Company Contact is required. Thank you.");
    			outputForm.txtCoContactName.focus();
    			return (false);
      			}
    
    		if (outputForm.txtCoPhone.value == "")
      			{
    			alert("The Company Phone Number is required. Thank you.");
    			outputForm.txtCoPhone.focus();
    			return (false);
      			}
    
    		
    		if (outputForm.txtCoFax.value == "")
      			{
    			alert("The Company Fax is required. Thank you.");
    			outputForm.txtCoFax.focus();
    			return (false);
      			}
    
    		if (outputForm.txtCoEmail.value == "")
      			{
    			alert("The Company Email is required. Thank you.");
    			outputForm.txtCoEmail.focus();
    			return (false);
      			}
    
    		if (outputForm.txtPONum.value == "")
      			{
    			alert("The Company Purchase Order Number is required. Thank you.");
    			outputForm.txtPONum.focus();
    			return (false);
      			}
    
    // service level radioButtons here
    		var r = document.forms[0].elements['radioServiceLevel'];//the radio buttons as a collection 
    		var param = 0; 
    		for(var i=0;i<r.length;i++){ 
    		
    		if (r[i].checked){param++} 
    			} 
    				if(param==0){ 
    						alert("Please choose your Level of Service. Thank you."); 
    				return false}  
    
    
    // Veh Pickup Here....
    //---------------------------------------------------------------------------------------------------------------
    
    		if (outputForm.txtVehName.value == "")
      			{
    			alert("The Vehicle Pickup Company Name is required. Thank you.");
    			outputForm.txtVehName.focus();
    			return (false);
      			}
    
    		if (outputForm.txtVehAddress.value == "")
      			{
    			alert("The Vehicle Pickup Company Address is required. Thank you.");
    			outputForm.txtVehAddress.focus();
    			return (false);
      			}
    
    		if (outputForm.txtVehCity.value == "")
      			{
    			alert("The Vehicle Pickup Company Head Office City is required. Thank you.");
    			outputForm.txtVehCity.focus();
    			return (false);
      			}
    
    
    		if (outputForm.VehState.value == "")
      			{
    			alert("The Vehicle Pickup Company State or Province is required. Thank you.");
    			outputForm.VehState.focus();
    			return (false);
      			}
    
    
    		if (outputForm.txtVehZip.value == "")
      			{
    			alert("The Vehicle Pickup Company Zip or Postal Code is required. Thank you.");
    			outputForm.txtVehZip.focus();
    			return (false);
      			}
    
    		if (outputForm.txtVehContactName.value == "")
      			{
    			alert("The Vehicle Pickup Company Contact is required. Thank you.");
    			outputForm.txtVehContactName.focus();
    			return (false);
      			}
    
    		if (outputForm.txtVehPhone.value == "")
      			{
    			alert("The Vehicle Pickup Company Phone Number is required. Thank you.");
    			outputForm.txtVehPhone.focus();
    			return (false);
      			}
    
    		
    		if (outputForm.txtVehFax.value == "")
      			{
    			alert("The Vehicle Pickup Company Fax is required. Thank you.");
    			outputForm.txtVehFax.focus();
    			return (false);
      			}
    
    		if (outputForm.txtVehEmail.value == "")
      			{
    			alert("The Vehicle Pickup Company Email is required. Thank you.");
    			outputForm.txtVehEmail.focus();
    			return (false);
      			}
    
    
    // Del Pickup Here....
    //---------------------------------------------------------------------------------------------------------------
    
    
    		if (outputForm.txtDelName.value == "")
      			{
    			alert("The Vehicle Delivery Company Name is required. Thank you.");
    			outputForm.txtDelName.focus();
    			return (false);
      			}
    
    		if (outputForm.txtDelAddress.value == "")
      			{
    			alert("The Vehicle Delivery  Company Address is required. Thank you.");
    			outputForm.txtDelAddress.focus();
    			return (false);
      			}
    
    		if (outputForm.txtDelCity.value == "")
      			{
    			alert("The Vehicle Delivery  Company Head Office City is required. Thank you.");
    			outputForm.txtDelCity.focus();
    			return (false);
      			}
    
    
    		if (outputForm.DelState.value == "")
      			{
    			alert("The Vehicle Delivery  Company State or Province is required. Thank you.");
    			outputForm.DelState.focus();
    			return (false);
      			}
    
    
    		if (outputForm.txtDelZip.value == "")
      			{
    			alert("The Vehicle Delivery  Company Zip or Postal Code is required. Thank you.");
    			outputForm.txtDelZip.focus();
    			return (false);
      			}
    
    		if (outputForm.txtDelContactName.value == "")
      			{
    			alert("The Vehicle Delivery  Company Contact is required. Thank you.");
    			outputForm.txtDelContactName.focus();
    			return (false);
      			}
    
    		if (outputForm.txtDelPhone.value == "")
      			{
    			alert("The Vehicle Delivery  Company Phone Number is required. Thank you.");
    			outputForm.txtDelPhone.focus();
    			return (false);
      			}
    
    		
    		if (outputForm.txtDelFax.value == "")
      			{
    			alert("The Vehicle Delivery  Company Fax is required. Thank you.");
    			outputForm.txtDelFax.focus();
    			return (false);
      			}
    
    		if (outputForm.txtDelEmail.value == "")
      			{
    			alert("The Vehicle Delivery  Company Email is required. Thank you.");
    			outputForm.txtDelEmail.focus();
    			return (false);
      			}
    
    	
    
    // Specific Vehicle Info Here....
    //---------------------------------------------------------------------------------------------------------------
    
    
    // truck value 
    		var r = document.forms[0].elements['radioValue'];//the radio buttons as a collection 
    		var param = 0; 
    		for(var i=0;i<r.length;i++){ 
    		
    		if (r[i].checked){param++} 
    			} 
    				if(param==0){ 
    						alert("Please indicate the Truck Value. Thank you."); 
    				return false}  
    
    
    // truck value CURRENCY
    		var r = document.forms[0].elements['radioDollars'];//the radio buttons as a collection 
    		var param = 0; 
    		for(var i=0;i<r.length;i++){ 
    		
    		if (r[i].checked){param++} 
    			} 
    				if(param==0){ 
    						alert("Please indicate the currency. Thank you."); 
    				return false}  
    
    
    
    // time sensitive
    		var r = document.forms[0].elements['radioTimeSensitive'];//the radio buttons as a collection 
    		var param = 0; 
    		for(var i=0;i<r.length;i++){ 
    		
    		if (r[i].checked){param++} 
    			} 
    				if(param==0){ 
    						alert("Please indicate if this order is Time Sensitive. Thank you."); 
    				return false}  
    
    
    
    
    		if (outputForm.txtVehReadyDate.value == "")
      			{
    			alert("The Vehicle Readiness Date is required in the proper format. Thank you.");
    			outputForm.txtVehReadyDate.focus();
    			return (false);
      			}
    
    
    		if (outputForm.txtVehPickupDate.value == "")
      			{
    			alert("The Required Pickup Date is required in the proper format. Thank you.");
    			outputForm.txtVehPickupDate.focus();
    			return (false);
      			}
    
    		if (outputForm.txtVehDeliveryDate.value == "")
      			{
    			alert("The Required Delivery Date is required in the proper format. Thank you.");
    			outputForm.txtVehDeliveryDate.focus();
    			return (false);
      			}
    
    // overdimensional
    		var r = document.forms[0].elements['radioDimensional'];//the radio buttons as a collection 
    		var param = 0; 
    		for(var i=0;i<r.length;i++){ 
    		
    		if (r[i].checked){param++} 
    			} 
    				if(param==0){ 
    						alert("Please indicate if this order is Overdimensional. Thank you."); 
    				return false}  
    
    
    
    		if (outputForm.txtVehYear.value == "")
      			{
    			alert("The Vehicle Year is required in the proper format. Thank you.");
    			outputForm.txtVehYear.focus();
    			return (false);
      			}
    
    
    		if (outputForm.txtVehMake.value == "")
      			{
    			alert("The Vehicle Make is required in the proper format. Thank you.");
    			outputForm.txtVehMake.focus();
    			return (false);
      			}
    
    		if (outputForm.txtVehModel.value == "")
      			{
    			alert("The Vehicle Model is required in the proper format. Thank you.");
    			outputForm.txtVehModel.focus();
    			return (false);
      			}
    
    
    		if (outputForm.txtUnit.value == "")
      			{
    			alert("The Vehicle Unit # is required in the proper format. Thank you.");
    			outputForm.txtUnit.focus();
    			return (false);
      			}
    
    		if (outputForm.txtSerial.value == "")
      			{
    			alert("The Vehicle Serial # is required in the proper format. Thank you.");
    			outputForm.txtSerial.focus();
    			return (false);
      			}
    
    // axel radio
    		var r = document.forms[0].elements['radioAxle#'];//the radio buttons as a collection 
    		var param = 0; 
    		for(var i=0;i<r.length;i++){ 
    		
    		if (r[i].checked){param++} 
    			} 
    				if(param==0){ 
    						alert("The Axel information is required. Thank you."); 
    				return false}  
    
    
    		if (outputForm.VehType.value == "")
      			{
    			alert("The Vehicle Type is required in the proper format. Thank you.");
    			outputForm.VehType.focus();
    			return (false);
      			}
    
    
    
    		return (true);
    	}
    	// STOP HIDING FROM OTHER BROWSERS -->
    </script>
    this works, in that it makes you validate the fields, but on the server, the form goes right thru...

    ???

    Jim

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Return false on any conditional that fails and use: onsubmit="return validate(this.name)"

  • #7
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Try this on and see if it works. Put the css is a stylesheet and it's reduced from 535 lines to 162 (Yeah, I was bored )

    Code:
    <html>
    	<head>
    		<style type="text/css">
    		body
    		{
    			font-family:verdana;
    		}
    		table
    		{
    			text-align:center;
    			background-color:#a1a1a1;
    		}
    		td
    		{
    			border:solid 1px;
    			border-color:#808080;
    		}
    		th
    		{
    			border:solid 1px;
    			border-color:#808080;
    		}
    		#topper
    		{
    			background-color:#CCCCCC;
    			width:100%;
    		}
    		#note
    		{
    			color:red;
    			font-weight:bold;
    			text-align:center;
    			width:100%;
    		}
    		.span3
    		{
    			background-color:#183DA8;
    			color:white;
    		}
    		.foot
    		{
    			font-weight:bold;
    			color:white;
    		}
    		#title
    		{
    			text-align:center;
    			width:100%;
    			font-weight:bold;
    			font-size:25px;
    		}	
    		</style>
    		<script type="text/javascript">
    		
    		function formValid()
    		{
    		
    			var chk=document.forms[0].elements['radioQuote'];
    			var stat=0;
    			var isall=0;
    			for(var i=0;i<chk.length;i++)
    			{
    				if(chk[i].checked)
    				{
    					stat=1;
    				}
    			}
    			if(stat!=1)
    			{
    				chk[0].style.background='red';
    				chk[1].style.background='red';
    				var isall=1;
    			}
    			chk=document.forms[0].elements['radioServiceLevel'];
    			stat=0;
    			for(var i=0;i<chk.length;i++)
    			{
    				if(chk[i].checked)
    				{
    					stat=1;
    				}
    			}
    			if(stat!=1)
    			{
    				chk[0].style.background='red';
    				chk[1].style.background='red';
    				chk[2].style.background='red';
    				isall=1;
    			}
    			var sel=document.forms[0].elements['CoState'].options[document.forms[0].elements['CoState'].selectedIndex];
    			if(sel.value=="")
    			{
    				sel.style.background='red';
    				isall=1;
    			}
    			for(var i=2;i<document.forms[0].length-5;i++)
    			{
    				if(i==5)
    				{
    				}
    				else
    				{
    					if(document.forms[0].elements[i].value=="")
    					{
    						isall=1;
    						document.forms[0].elements[i].style.borderColor='red';
    					}
    				}
    			}
    			if(isall==1)
    			{
    				alert('Please fill out the form completley missing fields are marked in red.');return false;
    			}
    			else
    			{
    				document.forms[0].submit();
    			}
    		}
    		</script>
    	</head>
    	<body>
    		<div id="topper">
    			<span id="title">Terms</span>
    			<ul>
    				<li>Payment terms are net 15 days from date of delivery</li>
    				<li>All first time shipments must be pre-paid</li>
    				<li>Credit Approval and account set-up takes 72 hours</li>
    				<li>We accept Visa & MasterCard</li>
    				<li>1 - 866 - DRV - STAR</li>
    			</ul>
    			<span id="note">Note - all fields must be completely filled in so that we can process your order!</span>
    		</div>
    		<form onsubmit="formValid();return false;" name="outputForm" method="post" action="sendOrderSingle.asp">
    			<table>
    				<tr>
    					<th colspan="3" class="span3">
    					Are you requesting an Order: <input type="radio" name="radioQuote" value="Order"> 
    					or a Quote <input type="radio" name="radioQuote" value="Order">
    					</th>
    				</tr>
    				<tr>
    					<td colspan="3" class="span3">Customer Information</td>
    				</tr>
    					<th>Company Name</th>
    					<th>Address</th>
    					<th>City</th>
    				</tr>
    				<tr>
    					<td><input type="text" name="txtCoName" size="30"></td>
    					<td><input type="text" name="txtCoAddress" size="30"></td>
    					<td><input type="text" name="txtCoCity" size="20"></td>
    				</tr>
    				<tr>
    					<th>State or Province</th>
    					<th>Zip/Postal Code</th>
    					<th>Contact Name</th>
    				</tr>
    				<tr>
    					<td>
    					<select size=1 name="CoState">
    							<option selected value="">Choose a Province or State...</option>
    							<option value="Alberta">Alberta</option>
    							<option value="British Columbia">British Columbia</option>
    							<option value="Manitoba">Manitoba</option>
    							<option value="New Brunswick">New Brunswick</option>
    							<option value="Newfoundland">Newfoundland</option>
    							<option value="North West Terrorties">North West Terrorties</option>
    							<option value="Nova Scotia">Nova Scotia</option>
    							<option value="Ontario">Ontario</option>
    							<option value="Prince Edward Island">Prince Edward Island</option>
    							<option value="Quebec">Quebec</option>
    							<option value="Saskatchewan">Saskatchewan</option>
    	           		</select>
    	           		</td>
    					<td><input type="text" name="txtCoZip" size="12"></td>
    					<td><input type="text" name="txtCoContactName" size="30"></td>
    				</tr>
    				<tr>
    					<th>Phone #</th>
    					<th>Fax</th>
    					<th>Email</th>
    				</tr>
    				<tr>
    					<td><input type="text" name="txtCoPhone" size="20"></td>
    					<td><input type="text" name="txtCoFax" size="12"></td>
    					<td><input type="text" name="txtCoEmail" size="30"></td>
    				</tr>
    				<tr>
    					<th>Purchase Order #</th>
    					<th colspan="2">Please Indicate Which Service Level You Require<br />   
    					<a href="services.asp" target="_blank"> Click here to review Service Levels....</a>
    					</th>
    				</tr>
    				<tr>
    					<td><input type="text" name="txtPONum" size="30"></td>
    					<td colspan="2">
    						Level A:<input type="radio" name="radioServiceLevel"  value="A">
    			
    						Level B:<input type="radio" name="radioServiceLevel"  value="B">
    	
    						Level C:<input type="radio" name="radioServiceLevel"  value="C"> 
    					</td>
    				</tr>
    				<tr>
    					<td class="foot">To send us your Order or Request a Quote, please click the SEND button...</td>
    					<td colspan="2"><input type="submit" value="SEND" name="SUBMIT">&nbsp;<input type="reset"></td>
    				</tr>
    			</table>
    		</form>
    	</body>
    </html>
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #8
    New Coder
    Join Date
    Jul 2002
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks Willy...

    yup, that was it. my SUBMIT syntax was missing that vital component...

    Added it and yup, she works fine now!

    Thanks one and all...geez I hate javascript...but it sure has it's uses, eh?



    Jim

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,032
    Thanks
    0
    Thanked 248 Times in 245 Posts
    You should still validate on the server-side as javascript can be disabled or even if not, the js validation can be bypassed. That's the rule of thumb.

  • #10
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    You should still validate on the server-side as javascript can be disabled or even if not, the js validation can be bypassed. That's the rule of thumb.
    JS is only useful in terms of validation when it's done to make data entry more user friendly, not as the data validator itself.
    *keep it simple (TM)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •