Click to See Complete Forum and Search --> : Need this to work in Netscape as well...
IndyB
06-24-2003, 02:10 PM
This little toggle script is working perfectly in IE, but in Netscape I get the following error:
Error: line 3: byCheck is not defined.
Is there something I can do to make this code work in both browsers?
Here's the js:
function changeit(){
if(document.frmpage.radio[0].checked){
byCheck.style.display="inline"
byCredit.style.display="none"
}
if(document.frmpage.radio[1].checked){
byCheck.style.display="none"
byCredit.style.display="inline"
}
}
Here's the form:
<form name="frmpage" action="" method="post">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="15%">Pay By Check</td>
<td width="85%"><input type="radio" name="radio" value="pay_check" onClick="changeit()"></td>
</tr>
<tr>
<td width="15%">Pay By Credit Card</td>
<td width="85%"><input type="radio" name="radio" value="pay_credit" onClick="changeit()"></td>
</tr>
</table>
</form>
Vladdy
06-24-2003, 02:29 PM
Use DOM methods to access page elements:
document.getElementById(elementID)
IndyB
06-24-2003, 02:40 PM
Thanks for your reply.
I'm not quite sure what you mean. I tried the following but it doesn't work...I'm probably way off. Could you explain?
function changeit(){
if(document.frmpage.radio[0].checked){
document.getElementById(byCheck).display="inline"
document.getElementById(byCredit).display="none"
//byCheck.style.display="inline"
//byCredit.style.display="none"
}
if(document.frmpage.radio[1].checked){
document.getElementById(byCheck).display="none"
document.getElementById(byCredit).display="inline"
//byCheck.style.display="none"
//byCredit.style.display="inline"
}
}
gil davis
06-24-2003, 02:48 PM
document.getElementById(byCheck).display="inline"
document.getElementById(byCredit).display="none"
change to
document.getElementById("byCheck").style.display = "inline"
document.getElementById("byCredit").style.display = "none"
IndyB
06-24-2003, 02:52 PM
Now it works in IE again, but still not in Netscape.
Netscape error says:
byCheck is not defined
and
document.getElementById is not a function.
Any ideas?
Vladdy
06-24-2003, 03:13 PM
You are not talking NS4.* are you???
IndyB
06-24-2003, 03:17 PM
I'm testing in Netscape 4.75
Netscape 4.x does not support the getElementById. Also, it is used by a very low percentage of users -- 1% (http://www.thecounter.com/stats/2003/May/browser.php)
IndyB
06-24-2003, 03:58 PM
True but tell that to my manager. There must be another way to accomplish this and have it work in Netscape.
Vladdy
06-24-2003, 05:15 PM
Use your "No JS" pages for NS 4.*
Making dynamic features work in it is not worth the time...
gil davis
06-25-2003, 07:50 AM
There are several things in your code besides just "getElementById()" that will keep NS 4.x from working with your page. It does not support the "style" attribute of an object, and it does not collapse an object when you change it's "display" attribute.
Also, NS 4.x only allows access to positioned objects with an ID (like a layer), and named objects like forms and images. Since you never posted the HTML for the objects called "byCheck" and "byCredit", that would be yet another hazard. If they happen to be form elements, then you have no chance of making them hide and still function as form elements.
If everyone stays with old browsers how are we to progress
NS4 will not be around forever .......Upgrade now
:D