PDA

View Full Version : Javascript Toggle Radio Buttons to Display Div


tek420angel
12-22-2004, 11:40 AM
Hey everyone... I need some help, please.. lol...

I have a make payment page in which I'm using javascript to toggle some radio buttons to display the different payment options. I have 3 options. Here is my javascript:


function toggle('Check', 'Credit', 'EasyPay' )
{
if (document.getElementById) {
target1 = document.getElementById('Check');
target2 = document.getElementById('Credit');
target3 = document.getElementById('EasyPay');

if (target1.style.display == "none"){
target1.style.display = "";
target2.style.display = "none";
target3.style.display = "none";
}

else if (target2.style.display == "none"){
target2.style.display = "";
target1.style.display = "none";
target3.style.display = "none";
}

else (target3.style.display == "none"){
target3.style.display = "";
target1.style.display = "none";
target2.style.display = "none";
}

It's not working at all. Now, I don't know if it makes any difference at all if my page is written all in php or not, but here's the section that contains my radio buttons:

print ("<div class=\"row3\"><p class=\"pmtheads2\">Please choose one:</span><label for=\"label5\">Check</label><span class=\"formw3\"><input name=\"PaymentType\" type=\"radio\" value=\"Check\" onClick=\"toggle('checkInfo', 'creditInfo', ','easyPay')\"id=\"label5\"></span>
<label for=\"label6\">Credit</label><span class=\"formw3\"><input name=\"PaymentType\" type=\"radio\" value=\"Credit\" onClick=\"toggle('creditInfo', 'easyPay', 'checkInfo')\" id=\"label6\" ></span>
<label for=\"label3\">EasyPay</label><span class=\"formw3\"><input name=\"PaymentType\" type=\"radio\" value=\"EasyPay\" onClick=\"toggle('easyPay', 'checkInfo', 'creditInfo')\" id=\"label3\"></span></div>
\n");

And then each option is contained within a div. Any ideas here? I can't get the toggle function to work at all. It displays nothing when I try it.
_________________
Tek Angel

gsoft
12-22-2004, 06:43 PM
Actually your right PHP makes no difference because once PHP has finished with it those slashes will be removied.


if (document.getElementById) {
target1 = document.getElementById('Check');
target2 = document.getElementById('Credit');
target3 = document.getElementById('EasyPay');


I think your missing a brace


if (document.getElementById) {
target1 = document.getElementById('Check');
target2 = document.getElementById('Credit');
target3 = document.getElementById('EasyPay');
}


You may find that in future indenting will solve such problems like this. Other than that I cant see any obvious errors.