#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    8
    Rep Power
    0

    javascript form validation in Netscape 6 failing


    I would aprreciate some suggetsions on this one. Thie javascript should check to see that either the payment1 or payment2 radio button is checked and if not alert the user to check one of them. Works fine in IE 6
    Here is the javascript:
    Code:
    <script language="javascript" type="text/javascript">
    	function checkit()
    	{
    		if (!document.final.payment1.checked && !document.final.payment2.checked)	{
    		alert('Please choose a payment method');
    		return false;
    		}
    		return true;
    	}
    </script>
    Here is the html form (a little asp is included in the values):
    Code:
    <form action="final.asp" method="get" name="final" onsubmit="return checkit();">
    		<input type="hidden" name="shipping" value="<%=shipping%>">
    		<input type="hidden" name="tax" value="<%=tax%>">
    		<input type="hidden" name="grandtotal" value="<%= grandtotal %>">
    		<input type="radio" name="payment1" value="cc">Credit Card <br />
    		<input type="radio" name="payment2" value="net30">Net 30 <br /> 
    </form>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    if (!document.getElementById("payment1").checked && !document.getElementById("payment2").checked) {
    ...

    this just sprang out of my mind after making all my IE scripts work with NN6 just within minutes

    there is probably also another way more similar to yours, but this should do the job too.

    did it work?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    8
    Rep Power
    0
    Unfornuately
    Code:
    if (!document.getElementById("payment1").checked && !document.getElementById("payment2").checked) {
    still doesn't work in Netscape 6 or Mozilla .99. Still works in IE 6 though. As before the form just submits as if there were no validation routines.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    8
    Rep Power
    0
    I just realized my form is inside a table. Could this be part of the problem? (That would really suck because the main content of this page (and every other in the site ) is inside a set of <td> </td> tags and every page calls header and footer includes).
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    ah, this COULD be a problem.
    you should use forms inside tables like this:
    Code:
    <form>
    <table>
    <tr>
    <td><input ...></td>
    </tr>
    </table>
    </form>
    did you check your code with a html validator? they do a great job on tracking down this kind of problem.
  10. #6
  11. No Profile Picture
    Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    Boston Ma.
    Posts
    1,529
    Rep Power
    0
    Hi


    That should not matter (tables).........

    PHP Code:
    <HTML>
    <
    HEAD>
    <
    script>
       
    Ctest false;
       function 
    checknow() {
       if (!
    Ctest) { 
        if (!(
    document.finish.payment1.checked)) {
              
    acheck 1;
           } else {
              
    acheck 2;
           }
          if (!(
    document.finish.payment2.checked)) {
              
    bcheck 1;
           } else {
              
    bcheck 2;
           }
          if ((
    acheck == 1)&&(bcheck == 1)) {
              
    alert("A Payment Method Has Not Been Selected");
            return;
          }
          if ((
    acheck == 2)&&(bcheck == 2)) {
            
    alert("Please Select Only One Payment Method");
              
    document.finish.payment2.checked=false;
              
    document.finish.payment1.checked=false;
            return;
          } else {
              var 
    Ctest true;
              
    document.finish.submit();
              return 
    true;
          } 
           }
            else 
          { 
        
    alert("Your request is being processed. Please wait."); 
       }
    }

    </script>
    </HEAD>
    <BODY>

    <form action="final.asp" method="get" name="finish">
            <input type="hidden" name="shipping" value="">
            <input type="hidden" name="tax" value="">
            <input type="hidden" name="grandtotal" value="">
            <input type="checkbox" name="payment1" value="cc">Credit Card <br>
            <input type="checkbox" name="payment2" value="net30">Net 30 <br>
                <input type="button" onclick="return checknow();" value="Submit">
    </form>
    </BODY>
    </HTML> 
    I used checkboxes, because it gives the user a chance to change there mind about there selection, where as RADIO/B's due not!



    F!
    Last edited by Fataqui; March 13th, 2002 at 05:48 PM.
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    8
    Rep Power
    0
    Still no go the form is now opened before the table and closed after the table.

    W3C html validator checks out except this:

    Code:
        *
    
    <script language="javascript" type="text/javascript">
    ^
    
          Error: element "SCRIPT" not allowed here; check which elements this element may be contained within
    This appreas to be a porblem with their validator to me ( could be wrong -- it has happened before) because the javascript appears at the very bottom of the page after everything esle (including </body> and </html>).
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    putting it in between <head>...</head> is the right place. but sorry, i donīt think this helps with your problem...

    btw: this output of w3c validator does not fit your script definition...
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    8
    Rep Power
    0
    Thanks fellows for the suggestions. Fataqui your script seems to stop the form submission but the alert boxes don't come up.

    In fact I can't seem to make a simple function with an alert box work in Netscape 6 .

    Code:
    <script type="text/javascript" Language="JavaScript 1.3">
      // var Ctest = false;
      function checkit() {
      // if (!Ctest) { 
      //  if ((!document.final.payment1.checked)||(!document.final.payment2.checked)) {
      //        alert("A Payment Method Has Not Been Selected");
      //      return;
      //    }
      //  if ((document.final.payment1.checked)&&(document.final.payment2.checked)) {
      //      alert("Please Select Only One Payment Method");
      //          document.final.payment2.checked=false;
      //          document.final.payment1.checked=false;
      //      return;
     //        } else {
     //   Ctest = true; 
     //   document.final.submit();
     //    return true;
     //     } 
     //      }
     //       else 
       //   { 
        alert("Your request is being processed. Please wait."); 
      // }
    }
    </script>
    I asm very frustrated so I think I will pick this up again tomrrow
  18. #10
  19. No Profile Picture
    Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    Boston Ma.
    Posts
    1,529
    Rep Power
    0
    Hi


    I redid the code in the other post, I checked it.........


    works in.............

    NS4/NS6/IEX4,5,6/OPERA5,6



    F!
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    8
    Rep Power
    0
    Thanks Fataqui

    Would you mine sharing the code you redid?
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    13
    final is a reserved word - in all versions of JavaScript -
    but not JScript (I'm not sure anything is reserved in JScript).


    ...only kidding, Bill...'finally'

    http://support.microsoft.com/default...;EN-US;q216528
  24. #13
  25. No Profile Picture
    Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    Boston Ma.
    Posts
    1,529
    Rep Power
    0
    Hi


    I told you I put it in my first post, in this topic!



    F!
  26. #14
  27. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    8
    Rep Power
    0
    Thanks for the help agaun folks. Here is where this is at

    I have a script that works in a stripped down html page in Netscape 6. Here it is:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    
    <body BGCOLOR="#FFFFFF">
    
    
    <form action="test.html" method="post" name="finish" onsubmit="return checkit();">
    
    Checkme1 <input name="payment1" type="checkbox"> <br/>
    Checkme2 <input name="payment2" type="checkbox"> <br/>
    <input type="submit" name="submit" value="submit">
    
    
    </form>
    
    
    
    </body>
    </html>
    
    <script language="javascript">
    function checkit()
    	{
    		if (!document.finish.payment1.checked && !document.finish.payment2.checked)	{
    			alert('Please check a box');
    			return false;
    			
    		}
    		if (document.finish.payment1.checked && document.finish.payment2.checked)	{
    			alert('Please make only one choice');
    			return false;
    		}
    		return true;
    	}
    </script>

    But when I put it in with my full blown html page it stops working.
    Here is the full page script and all (page checks out with the w3c validator):

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> Leading American Attorneys -- Members Store </TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    
    <style type="text/css" media="screen">
    	td {
    	font-family : Verdana, Arial, Helvetica, sans-serif;
    	font-size : 12px;
    	color : #000000;
    	}
    a:link	{
    		color: #000099;
    		text-decoration: underline;		
    	}
    a:visited	{
    		color: purple;	
    		text-decoration: underline;		
    	}
    a:hover	{
    		color: red;		
    		text-decoration: underline;
    	}
    
    </style>
    
    </HEAD>
    <BODY BGCOLOR="#FFFFFF">
    
    <!-- ImageReady Slices (brochurepage.psd) -->
    
    
    	
    <form action="final.asp" method="get" name="finish" onSubmit="return checkit();">
    <TABLE WIDTH="662" border="0" CELLPADDING="0" CELLSPACING="0">
    	<tr>
    		<td><IMG SRC="../images/MembersHeader_01.gif" WIDTH="278" HEIGHT="205" BORDER="0" USEMAP="#MembersHeader_01_Map" alt="Leading American Attorneys Navigation"></td>
    		<td> <IMG SRC="../images/MembersHeader_02.gif" WIDTH="384" HEIGHT="180" alt="Leading American Attorneys"> </td>
    	</tr>
    		<tr>
    		<td>    </td>
    		<td> 
    <table><tr bgcolor='silver'><td> <b>James Ryan </b></td></tr>
    <tr><td>Attorney at Law   </td></tr>
    <tr><td>4221 IDS Center </td></tr>
    <tr bgcolor='silver'><td>80 South Eighth Street </td></tr>
    <tr><td>Minneapolis, MN 55402</td></tr>
    </table>
    	<table width="350" border="0" cellspacing='2' cellpadding='3'>	
    	<tr bgcolor='silver'>
    
    			<td width='250'><B>Product</B></td> 
    			<td width='33'><B>Quantity</B></td>
    			<td width='33'><B>Price</B></td>
    			<td width='34'> <B>LineTotal</B> </td>
    		</tr>  
     <tr><td width='250'>Certificate  </td> <td width='33'>1 </td> <td width='33'> $100.00 </td> <td width='34'>$100.00 </td></tr><tr bgcolor='silver'><td width='300' colspan='3'><b>Subtotal </b></td><td width='50'> <b>$100.00 </b></td></tr><tr><td colspan='3'> <b>Shipping </b></td><td width='50'> <b>$15.00 </b></td></tr><tr bgcolor='silver'><td colspan='3'> <b>Tax </b></td><td width='50'> <b>$8.05 </b></td></tr><tr><td colspan='3'> <b>Grand Total </b></td><td width='50'> <b>$123.05 </b></td></tr><tr bgcolor='silver'>
    <td colspan='4'> 
    	
    	
    		Please choose payment method: credit card or Net 30 (paying by credit card entitles you to a 10% discount). <br />
    		<input type="hidden" name="shipping" value="15">
    		<input type="hidden" name="tax" value="8.05">
    		<input type="hidden" name="grandtotal" value="123.05">
    		<input type="checkbox" name="payment1" value="cc">Credit Card <br />
    		<input type="checkbox" name="payment2" value="net30">Net 30 <br />
    		
    </td>
    <tr>
    <td colspan='4'>
    	  <input type="submit" name="submit" value="Submit">
    	  <input type="reset">
    </td>
    </tr>
    </table>
    
    
    		</td>
    	</tr>
    </table>
    
    
    
    </form>
    <!-- End ImageReady Slices -->
    <MAP NAME="MembersHeader_01_Map">
    <AREA SHAPE="rect" ALT="" COORDS="120,24,211,46" HREF="http://www.lawlead.com/stubs/index.lasso">
    <AREA SHAPE="rect" ALT="" COORDS="83,54,173,84" HREF="http://www.lawlead.com/stubs/members/services.lasso">
    <AREA SHAPE="rect" ALT="" COORDS="66,99,168,126" HREF="http://www.lawlead.com/stubs/members/update.lasso">
    <AREA SHAPE="rect" ALT="" COORDS="52,142,223,167" HREF="http://www.lawlead.com/stubs/members/saying.lasso">
    </MAP>
    
    
    </BODY>
    </HTML>
    
    
    
    <script type="text/javascript" Language="JavaScript 1.3">
    function checkit()
    	{
    		if (!document.finish.payment1.checked && !document.finish.payment2.checked)	{
    			alert('Please check a box');
    			return false;
    			
    		}
    		if (document.finish.payment1.checked && document.finish.payment2.checked)	{
    			alert('Please make only one choice');
    			return false;
    		}
    		return true;
    	}
    </script>

IMN logo majestic logo threadwatch logo seochat tools logo