The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
javascript form validation in Netscape 6 failing
Discuss javascript form validation in Netscape 6 failing in the JavaScript Development forum on Dev Shed. javascript form validation in Netscape 6 failing JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 13th, 2002, 02:39 PM
|
|
Junior Member
|
|
Join Date: Mar 2002
Posts: 8
Time spent in forums: < 1 sec
Reputation 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>
|

March 13th, 2002, 02:51 PM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
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?
|

March 13th, 2002, 03:01 PM
|
|
Junior Member
|
|
Join Date: Mar 2002
Posts: 8
Time spent in forums: < 1 sec
Reputation 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.
|

March 13th, 2002, 03:46 PM
|
|
Junior Member
|
|
Join Date: Mar 2002
Posts: 8
Time spent in forums: < 1 sec
Reputation 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).
|

March 13th, 2002, 03:54 PM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
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.
|

March 13th, 2002, 04:30 PM
|
|
Senior Member
|
|
Join Date: Nov 2001
Location: Boston Ma.
Posts: 1,529
Time spent in forums: 24 m 42 sec
Reputation 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.
|

March 13th, 2002, 04:33 PM
|
|
Junior Member
|
|
Join Date: Mar 2002
Posts: 8
Time spent in forums: < 1 sec
Reputation 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>).
|

March 13th, 2002, 04:36 PM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
|
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...
|

March 13th, 2002, 04:54 PM
|
|
Junior Member
|
|
Join Date: Mar 2002
Posts: 8
Time spent in forums: < 1 sec
Reputation 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 
|

March 13th, 2002, 04:59 PM
|
|
Senior Member
|
|
Join Date: Nov 2001
Location: Boston Ma.
Posts: 1,529
Time spent in forums: 24 m 42 sec
Reputation Power: 0
|
|
|
Hi
I redid the code in the other post, I checked it.........
works in.............
NS4/NS6/IEX4,5,6/OPERA5,6
F!
|

March 13th, 2002, 05:19 PM
|
|
Junior Member
|
|
Join Date: Mar 2002
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Thanks Fataqui
Would you mine sharing the code you redid?
|

March 13th, 2002, 05:44 PM
|
|
Contributing User
|
|
Join Date: Nov 2001
Posts: 765
Time spent in forums: 3 m 45 sec
Reputation Power: 12
|
|
|

March 13th, 2002, 05:49 PM
|
|
Senior Member
|
|
Join Date: Nov 2001
Location: Boston Ma.
Posts: 1,529
Time spent in forums: 24 m 42 sec
Reputation Power: 0
|
|
|
Hi
I told you I put it in my first post, in this topic!
F!
|

March 14th, 2002, 10:15 AM
|
|
Junior Member
|
|
Join Date: Mar 2002
Posts: 8
Time spent in forums: < 1 sec
Reputation 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>
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|