Forum Moderators: open

Message Too Old, No Replies

Javascript Toggle Radio Buttons to Display Div

~ramming head into wall repeatedly~

         

tek420angel

7:26 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



Hi there. I'm extremely frustrated and any amount of help would be super appreciated.

I've got three radio buttons. I've got three div's of content I want displayed when clicking on one of the radio buttons. I want only one div to be displayed at a time.

It just won't work and I've tried about everything I can find online about toggling and javascript. I refuse to believe that this is really that difficult even for a novice js user like myself. In any case, I figured that as desperate as I'm becoming, it can't hurt to share the problem with some experts and see if I can't get some answers. SO! This is the script I've been working with as of now:


function toggle( targetOpen, targetClose, targetClose2 ){
if (document.getElementById)
{
targetO = document.getElementById( targetOpen );
targetC = document.getElementById( targetClose );
targetC2 = document.getElementById( targetClose2 );
if (targetO.style.display == "none"){
targetO.style.display = "";targetC.style.display = "none";
targetC2.style.display = "none";
}
else {targetO.style.display = "none";}
}
}

And here are my radio buttons:

[code]

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

adni18

7:33 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



print ("<div class=\

this opens up the print dialog in IE. try document.write()

adni18

7:35 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, make sure you have included the <BODY> tag. That makes a major difference in some browsers.

adni18

7:38 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"id=\"Check\"></

make sure you put a space in between the " and the id=

tek420angel

7:38 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



Okay, well I do have a body tag. I might be confused about where you're talking about placing the "document.write()"
If I place it in from of my div stuff:

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

then I get this:

Fatal error: Call to undefined function: write() in /var/www/html/jamie/pbs/MakePaymentMINE.php on line 392

adni18

7:40 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



also:

if (document.getElementById)

should be

if (document.getElementById())

tek420angel

7:59 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



Mkay, thanks, however, none of those issues solve my problem. I still can't toggle.

Lance

9:00 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



I didn't disect your code to see what was wrong, but see if this will give you an easier starting point.


<style type="text/css">
#Div1, #Div2, #Div3
{
DISPLAY: none;
}
</style>

<script type="text/javascript">
function Toggle(theDiv) {
document.getElementById("Div1").style.display = "none";
document.getElementById("Div2").style.display = "none";
document.getElementById("Div3").style.display = "none";
document.getElementById(theDiv).style.display = "block";
}
</script>

<input type="radio" name="ToggleDivs" onclick="Toggle('Div1');" />Turn on Div 1<br />
<input type="radio" name="ToggleDivs" onclick="Toggle('Div2');" />Turn on Div 2<br />
<input type="radio" name="ToggleDivs" onclick="Toggle('Div3');" />Turn on Div 3<br />

<br /><br />

<div id="Div1">I am the content of Div 1</div>

<div id="Div2">I am the content of Div 2</div>

<div id="Div3">I am the content of Div 3</div>

adni18

9:09 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oooh. So you're putting the print ("") function in your php code! I thought you were using it as a javascript code.

tek420angel

9:38 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



is there anyway that because my form stuff is written in php that this would not be working? I took your code and adapted it to work with mine and I'm getting really angry now because there's no reason it shouldn't be working as far as I can see... I've dissected and redissected this crap over and over again...

adni18

10:20 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<style type="text/css">
#Div1, #Div2, #Div3
{
DISPLAY: none;
}
</style>
<script type="text/javascript">
function Toggle(theDiv) {
document.getElementById("Div1").style.display = "none";
document.getElementById("Div2").style.display = "none";
document.getElementById("Div3").style.display = "none";
document.getElementById(theDiv).style.display = "block";
}
</script>

print ("Please choose one:<br>\n<input type=\"radio\" name=\"ToggleDivs\" onclick=\"Toggle('Div1');\" id=\"Check\" />\n<label for=\"Check\">Check</label>\n<br /> \n<input type=\"radio\" name=\"ToggleDivs\" onclick=\"Toggle('Div2');\" id=\"Credit\" />\n<label for=\"Credit\">Credit</label>\n<br /> \n<input type=\"radio\" name=\"ToggleDivs\" onclick=\"Toggle('Div3');\" id=\"EasyPay\" />\n<label for=\"EasyPay\">EasyPay</label>\n<br /> \n<br /> \n<br /> \n
<div id=\"Div1\">The user wants to pay with a check.</div> \n<div id=\"Div2\">They want to use a credit card.</div> \n<div id=\"Div3\">The guy takes the easy way out with EasyPay.</div>")

tek420angel

2:36 pm on Dec 30, 2004 (gmt 0)

10+ Year Member



UGH! I have it working. I figured out why it wasn't working. It was my JS Validation script! How terrible...

Thanks for all your help!