...

View Full Version : radio buttons refer to wrong part of program



dp76
10-09-2012, 04:58 PM
Hello,

I am trying to build a webpage where a user answers a question (radio button) and once the answer is submitted the results of a survey of these questions is revealed. I have managed (after a long struggle) to do this for the first question. I assumed that cutting and pasting the same code and altering the ids I could add other questions. This is not the case. Answering the radio button on the second question the original answers are revealed under the first question.

I am at a total loss as why this has happened

Any help greatly appreciated

code below
[CODE]
<div class="q1">
<table width="100%">
<tbody>
<tr>



<table width="100%" border="0" cellpadding="0" cellspacing="0">

</tr>
<tr>
<td width="20%">I need to be on my guard against others</td>

<td width="15%"align="center"> <label class="choice">
<input id="Check" name="field_Payment" type="radio" value="rarely" class="required" onclick="toggle('show');">
Rarely</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="Paypal" name="field_Payment" type="radio" value="monthly" class="required" onclick="toggle('show');">
Once a month</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="weekly" name="field_Payment" type="radio" value="weekly" class="required" onclick="toggle('show');">
Once a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="several" name="field_Payment" type="radio" value="several" class="required" onclick="toggle('show');">
Several times a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="daily" name="field_Payment" type="radio" value="daily" class="required" onclick="toggle('show');">
Once a day</label></td>

</table></td>
</tr>



<div class="q1" style="display:none" id="mytext">


<tr>
<td>

<table width="100%" border="0" cellpadding="1" cellspacing="0">
</td>

<td width="20%">Our survey said:</td>
<td width="15%" align="center"> 31%</td>
<td width="15%" align="center"> 17%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">10%</td>
</tr>

</div>

</table>
</td>
</tr>


</div>



<div class="q2">
<table width="100%">
<tbody>
<tr>



<table width="100%" border="0" cellpadding="0" cellspacing="0">

</tr>
<tr>
<td width="20%">Negative comments about me might be being put around </td>

<td width="15%"align="center"> <label class="choice2">
<input id="Check2" name="field_Payment2" type="radio" value="rarely2" class="required" onclick="toggle('show');">
Rarely</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="Paypal2" name="field_Payment2" type="radio" value="monthly2" class="required" onclick="toggle('show');">
Once a month</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="weekly2" name="field_Payment2" type="radio" value="weekly2" class="required" onclick="toggle('show');">
Once a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="several2" name="field_Payment2" type="radio" value="several2" class="required" onclick="toggle('show');">
Several times a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="daily2" name="field_Payment2" type="radio" value="daily2" class="required" onclick="toggle('show');">
Once a day</label></td>

</table></td>
</tr>



<div class="q2" style="display:none" id="mytext">


<tr>
<td>

<table width="100%" border="0" cellpadding="1" cellspacing="0">
</td>

<td width="20%">Our survey said:</td>
<td width="15%" align="center"> 35%</td>
<td width="15%" align="center"> 24%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">14%</td>
<td width="15%" align="center">7%</td>
</tr>


</table>
</td>
</tr>



</div>
[/ICODE]

WolfShade
10-09-2012, 05:04 PM
After a cursory glance, the only thing I can tell you is that you have improperly nested tags. Example: an opening TABLE tag immediately before a closing TD tag.

Get that corrected, and inserted in between CODE tags, and that will help you get help.

dp76
10-09-2012, 05:14 PM
As you can see I am very new! I have chnaged the tags... thought I did add the
tages.

Code below

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>


<title>Paranoid Thoughts</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>



<link rel="stylesheet" href="paranoidthoughts.css" type="text/css"
media="screen" />



<script type="text/javascript">
function toggle(value){
if(value=='show') { document.getElementById('mytext').style.display='block'; }
else { document.getElementById('mytext').style.display='none'; }
}
</script>

<style type="text/css">

</style>
</head>
<body>
<div id="wrap">

<div id="header">

<img src="paranoidimages/logos.png" alt="IoP Logo"> <br />
<img src="paranoidimages/oxfordlogo.jpg" alt="Oxford Logo">
</div>
<div id="header1">
<img src="paranoidimages/slam_logo.gif" alt="Slam Logo">
&nbsp
<img src="paranoidimages/Wellcome_Trust.jpg" alt"Wellcome logo">
</div>

<div id="parlogo">
<img alt='Paranoid thoughts' src='paranoidimages/logo.gif' border='0'/>
</div>
<div id="colortest">
</div>
<?php require_once('menu.php'); ?>

<h1>Assess your paranoia</h1>
<p>It's rare to go through life without having a paranoid thought. But how many people get these thoughts frequently?</p>
<p>We recently surveyed over a thousand people to see how many regularly had suspicious thoughts.</p>
<p>As you enter your response in the table below the results from the survey will be revealed.</p>

<p><em>Please note that this questionnaire only works in the Internet Explorer web browser.</em></p>
<h2>Paranoid thoughts questionnaire</h2>



<div class="q1">
<table width="100%">
<tbody>
<tr>



<table width="100%" border="0" cellpadding="0" cellspacing="0">

</tr>
<tr>
<td width="20%">I need to be on my guard against others</td>

<td width="15%"align="center"> <label class="choice">
<input id="Check" name="field_Payment" type="radio" value="rarely" class="required" onclick="toggle('show');">
Rarely</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="Paypal" name="field_Payment" type="radio" value="monthly" class="required" onclick="toggle('show');">
Once a month</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="weekly" name="field_Payment" type="radio" value="weekly" class="required" onclick="toggle('show');">
Once a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="several" name="field_Payment" type="radio" value="several" class="required" onclick="toggle('show');">
Several times a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="daily" name="field_Payment" type="radio" value="daily" class="required" onclick="toggle('show');">
Once a day</label></td>

</table></td>
</tr>



<div class="q1" style="display:none" id="mytext">


<tr>
<td>

<table width="100%" border="0" cellpadding="1" cellspacing="0">


<td width="20%">Our survey said:</td>
<td width="15%" align="center"> 31%</td>
<td width="15%" align="center"> 17%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">10%</td>
</tr>

</div>

</table>
</td>
</tr>


</div>



<div class="q2">
<table width="100%">
<tbody>
<tr>



<table width="100%" border="0" cellpadding="0" cellspacing="0">

</tr>
<tr>
<td width="20%">Negative comments about me might be being put around </td>

<td width="15%"align="center"> <label class="choice2">
<input id="Check2" name="field_Payment2" type="radio" value="rarely2" class="required" onclick="toggle('show');">
Rarely</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="Paypal2" name="field_Payment2" type="radio" value="monthly2" class="required" onclick="toggle('show');">
Once a month</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="weekly2" name="field_Payment2" type="radio" value="weekly2" class="required" onclick="toggle('show');">
Once a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="several2" name="field_Payment2" type="radio" value="several2" class="required" onclick="toggle('show');">
Several times a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="daily2" name="field_Payment2" type="radio" value="daily2" class="required" onclick="toggle('show');">
Once a day</label></td>

</table></td>
</tr>



<div class="q2" style="display:none" id="mytext">


<tr>
<td>

<table width="100%" border="0" cellpadding="1" cellspacing="0">


<td width="20%">Our survey said:</td>
<td width="15%" align="center"> 35%</td>
<td width="15%" align="center"> 24%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">14%</td>
<td width="15%" align="center">7%</td>
</tr>


</table>
</td>
</tr>



</div>

</body>
</html>

xelawho
10-09-2012, 05:23 PM
you cannot have 2 elements with the same ID - this will lead to exactly this type of problem.

try changing your my text divs to

<div class="q1" style="display:none" id="mytext1">
and

<div class="q1" style="display:none" id="mytext2">

and passing in the div id on the radio button click:


<input id="Check2" name="field_Payment2" type="radio" value="rarely2" <input id="Check" name="field_Payment" type="radio" value="rarely" class="required" onclick="toggle('show','mytext1');">


and letting your function accept that as an parameter:



function toggle(value,divid){
if(value=='show') { document.getElementById(divid).style.display='block'; }
else { document.getElementById(divid).style.display='none'; }
}


(although I can't see what the "else" is doing in the function...)

jmrker
10-09-2012, 06:38 PM
And you still have un-matched <table>, <tr> and <td> tag sequences.

You also should not put code between tags, like: </td> &nbsp; <td> and </tr> <div> ... </div> <tr>

WolfShade
10-09-2012, 07:24 PM
<table>
<tr>
<td></td>
</tr>
</table>
Nothing in between. Anything else is not proper HTML, exception being if you are working in a server-side dynamic language.

jmrker
10-09-2012, 07:36 PM
And you still have un-matched <table>, <tr> and <td> tag sequences.

You also should not put code between tags, like: </td> &nbsp; <td> and </tr> <div> ... </div> <tr>




<table>
<tr>
<td></td>
</tr>
</table>
Nothing in between. Anything else is not proper HTML, exception being if you are working in a server-side dynamic language.

That's what I was trying to say. ;)

dp76
10-10-2012, 10:49 AM
Thanks all....I have made the changes...now no answers show!

other ideas very much appreciated

xelawho
10-10-2012, 01:37 PM
can you show us your revised code?

dp76
10-10-2012, 02:20 PM
yes...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>


<title>Paranoid Thoughts</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>



<link rel="stylesheet" href="paranoidthoughts.css" type="text/css"
media="screen" />



<script type="text/javascript">
function toggle(value,divid){
if(value=='show') { document.getElementById('divid').style.display='block'; }
else { document.getElementById('divid').style.display='none'; }
}
</script>

<style type="text/css">

</style>
</head>
<body>
<div id="wrap">

<div id="header">

<img src="paranoidimages/logos.png" alt="IoP Logo"> <br />
<img src="paranoidimages/oxfordlogo.jpg" alt="Oxford Logo">
</div>
<div id="header1">
<img src="paranoidimages/slam_logo.gif" alt="Slam Logo">
&nbsp
<img src="paranoidimages/Wellcome_Trust.jpg" alt"Wellcome logo">
</div>

<div id="parlogo">
<img alt='Paranoid thoughts' src='paranoidimages/logo.gif' border='0'/>
</div>
<div id="colortest">
</div>
<?php require_once('menu.php'); ?>

<h1>Assess your paranoia</h1>
<p>It's rare to go through life without having a paranoid thought. But how many people get these thoughts frequently?</p>
<p>We recently surveyed over a thousand people to see how many regularly had suspicious thoughts.</p>
<p>As you enter your response in the table below the results from the survey will be revealed.</p>

<p><em>Please note that this questionnaire only works in the Internet Explorer web browser.</em></p>
<h2>Paranoid thoughts questionnaire</h2>



<div class="q1">
<table width="100%">

<tr>



<table width="100%" border="0" cellpadding="0" cellspacing="0">

<td width="20%">I need to be on my guard against others</td>


<td width="15%"align="center"> <label class="choice">
<input id="Check" name="field_Payment" type="radio" value="rarely" class="required" onclick="toggle('show');">
Rarely</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice">
<input id="Paypal" name="field_Payment" type="radio" value="monthly" class="required" onclick="toggle('show');">
Once a month</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice">
<input id="weekly" name="field_Payment" type="radio" value="weekly" class="required" onclick="toggle('show');">
Once a week</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice">
<input id="several" name="field_Payment" type="radio" value="several" class="required" onclick="toggle('show');">
Several times a week</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice">
<input id="daily" name="field_Payment" type="radio" value="daily" class="required" onclick="toggle('show');">
Once a day</label></td>
</tr>
</table>


<div class="q1" style="display:none" id="mytext1">

<table width="100%" border="0" cellpadding="1" cellspacing="0">

<tr>




<td width="20%">Our survey said:</td>
<td width="15%" align="center"> 31%</td>
<td width="15%" align="center"> 17%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">10%</td>
</tr>

</div>

</table>
</td>
</tr>


</div>



<div class="q1" id="myText2">

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>






<td width="20%">Negative comments about me might be being put around </td>

<td width="15%"align="center"> <label class="choice2">
<input id="Check2" name="field_Payment2" type="radio" value="rarely2" class="required" onclick="toggle('show','mytext2');">
Rarely</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice2">
<input id="Paypal2" name="field_Payment2" type="radio" value="monthly2" class="required" onclick="toggle('show, 'mytext2');">
Once a month</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice2">
<input id="weekly2" name="field_Payment2" type="radio" value="weekly2" class="required" onclick="toggle('show', 'mytext2');">
Once a week</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice2">
<input id="several2" name="field_Payment2" type="radio" value="several2" class="required" onclick="toggle('show', 'mytext2');">
Several times a week</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice2">
<input id="daily2" name="field_Payment2" type="radio" value="daily2" class="required" onclick="toggle('show', 'mytext2');">
Once a day</label></td>
</tr>
</table>




<div class="q1" style="display:none" id="mytext2">

<table>

<table width="100%" border="0" cellpadding="1" cellspacing="0">
<tr>

<td width="20%">Our survey said:</td>
<td width="15%" align="center"> 35%</td>
<td width="15%" align="center"> 24%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">14%</td>
<td width="15%" align="center">7%</td>
</tr>


</table>



</div>

</body>
</html>

xelawho
10-10-2012, 02:27 PM
two things - all your radio buttons should be passing the div id to the function, so the ones from question one would look like this:

<input id="Check" name="field_Payment" type="radio" value="rarely" class="required" onclick="toggle('show','mytext1');">

the other thing is that divid in your function is a variable, so remove the quote marks which are making it a string:


function toggle(value,divid){
if(value=='show') { document.getElementById(divid).style.display='block'; }
else { document.getElementById(divid).style.display='none'; }
}

dp76
10-10-2012, 02:56 PM
Sadly this made no diffrenece at all. No answers appear when radio button is selected



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>


<title>Paranoid Thoughts</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>



<link rel="stylesheet" href="paranoidthoughts.css" type="text/css"
media="screen" />



<script type="text/javascript">
function toggle(value,divid){
if(value==show) { document.getElementById('divid').style.display=block; }
else { document.getElementById('divid').style.display=none; }
}
</script>

<style type="text/css">

</style>
</head>
<body>
<div id="wrap">

<div id="header">

<img src="paranoidimages/logos.png" alt="IoP Logo"> <br />
<img src="paranoidimages/oxfordlogo.jpg" alt="Oxford Logo">
</div>
<div id="header1">
<img src="paranoidimages/slam_logo.gif" alt="Slam Logo">
&nbsp
<img src="paranoidimages/Wellcome_Trust.jpg" alt"Wellcome logo">
</div>

<div id="parlogo">
<img alt='Paranoid thoughts' src='paranoidimages/logo.gif' border='0'/>
</div>
<div id="colortest">
</div>
<?php require_once('menu.php'); ?>

<h1>Assess your paranoia</h1>
<p>It's rare to go through life without having a paranoid thought. But how many people get these thoughts frequently?</p>
<p>We recently surveyed over a thousand people to see how many regularly had suspicious thoughts.</p>
<p>As you enter your response in the table below the results from the survey will be revealed.</p>

<p><em>Please note that this questionnaire only works in the Internet Explorer web browser.</em></p>
<h2>Paranoid thoughts questionnaire</h2>



<div class="q1" id="mytext1">
<table width="100%">

<tr>



<table width="100%" border="0" cellpadding="0" cellspacing="0">

<td width="20%">I need to be on my guard against others</td>


<td width="15%"align="center"> <label class="choice">
<input id="Check" name="field_Payment" type="radio" value="rarely" class="required" onclick="toggle('show','mytext1');">
Rarely</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice">
<input id="Paypal" name="field_Payment" type="radio" value="monthly" class="required" onclick="toggle('show','mytext1');">
Once a month</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice">
<input id="weekly" name="field_Payment" type="radio" value="weekly" class="required" onclick="toggle('show','mytext1');">
Once a week</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice">
<input id="several" name="field_Payment" type="radio" value="several" class="required" onclick="toggle('show','mytext1');">
Several times a week</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice">
<input id="daily" name="field_Payment" type="radio" value="daily" class="required" onclick="toggle('show','mytext1');">
Once a day</label></td>
</tr>
</table>


<div class="q1" style="display:none" id="mytext1">

<table width="100%" border="0" cellpadding="1" cellspacing="0">

<tr>




<td width="20%">Our survey said:</td>
<td width="15%" align="center"> 31%</td>
<td width="15%" align="center"> 17%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">10%</td>
</tr>

</div>

</table>
</td>
</tr>


</div>



<div class="q1" id="mytext2">

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>






<td width="20%">Negative comments about me might be being put around </td>

<td width="15%"align="center"> <label class="choice2">
<input id="Check2" name="field_Payment2" type="radio" value="rarely2" class="required" onclick="toggle('show','mytext2');">
Rarely</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice2">
<input id="Paypal2" name="field_Payment2" type="radio" value="monthly2" class="required" onclick="toggle('show,'mytext2');">
Once a month</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice2">
<input id="weekly2" name="field_Payment2" type="radio" value="weekly2" class="required" onclick="toggle('show','mytext2');">
Once a week</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice2">
<input id="several2" name="field_Payment2" type="radio" value="several2" class="required" onclick="toggle('show','mytext2');">
Several times a week</label></td>
&nbsp

<td width="15%"align="center"> <label class="choice2">
<input id="daily2" name="field_Payment2" type="radio" value="daily2" class="required" onclick="toggle('show','mytext2');">
Once a day</label></td>
</tr>
</table>




<div class="q1" style="display:none" id="mytext2">

<table>

<table width="100%" border="0" cellpadding="1" cellspacing="0">
<tr>

<td width="20%">Our survey said:</td>
<td width="15%" align="center"> 35%</td>
<td width="15%" align="center"> 24%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">14%</td>
<td width="15%" align="center">7%</td>
</tr>


</table>



</div>

</body>
</html>

xelawho
10-10-2012, 03:05 PM
the other thing is that divid in your function is a variable, so remove the quote marks which are making it a string:



function toggle(value,divid){
if(value=='show') { document.getElementById(divid).style.display='block'; }
else { document.getElementById(divid).style.display='none'; }
}

dp76
10-10-2012, 03:25 PM
thanks for your continued help but with or without quotes there is no diffrence...I have tried both, or have I missed somethiing?

xelawho
10-10-2012, 03:43 PM
sorry, I wasn't paying attention at how awry you have gone. The function should look like this:


function toggle(value,divid){
if(value=="show") { document.getElementById(divid).style.display="block"; }
else { document.getElementById(divid).style.display="none"; }
}


your code in post #12 has two elements each sharing the same ID. So we're back to square one. It works if your html looks like this:


<body>
<div id="wrap">
<div id="header">
<img src="paranoidimages/logos.png" alt="IoP Logo"> <br />
<img src="paranoidimages/oxfordlogo.jpg" alt="Oxford Logo">
</div>
<div id="header1">
<img src="paranoidimages/slam_logo.gif" alt="Slam Logo">
&nbsp
<img src="paranoidimages/Wellcome_Trust.jpg" alt"Wellcome logo">
</div>
<div id="parlogo">
<img alt='Paranoid thoughts' src='paranoidimages/logo.gif' border='0'/>
</div>
<div id="colortest">
</div>
<?php require_once('menu.php'); ?>
<h1>Assess your paranoia</h1>
<p>It's rare to go through life without having a paranoid thought. But how many people get these thoughts frequently?</p>
<p>We recently surveyed over a thousand people to see how many regularly had suspicious thoughts.</p>
<p>As you enter your response in the table below the results from the survey will be revealed.</p>
<p><em>Please note that this questionnaire only works in the Internet Explorer web browser.</em></p>
<h2>Paranoid thoughts questionnaire</h2>
<div class="q1" >
<table width="100%">
<tr>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<td width="20%">I need to be on my guard against others</td>
<td width="15%"align="center"> <label class="choice">
<input id="Check" name="field_Payment" type="radio" value="rarely" class="required" onclick="toggle('show','mytext1');">
Rarely</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="Paypal" name="field_Payment" type="radio" value="monthly" class="required" onclick="toggle('show','mytext1');">
Once a month</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="weekly" name="field_Payment" type="radio" value="weekly" class="required" onclick="toggle('show','mytext1');">
Once a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="several" name="field_Payment" type="radio" value="several" class="required" onclick="toggle('show','mytext1');">
Several times a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice">
<input id="daily" name="field_Payment" type="radio" value="daily" class="required" onclick="toggle('show','mytext1');">
Once a day</label></td>
</tr>
</table>
<div class="q1" style="display:none" id="mytext1">
<table width="100%" border="0" cellpadding="1" cellspacing="0">
<tr>
<td width="20%">Our survey said:</td>
<td width="15%" align="center"> 31%</td>
<td width="15%" align="center"> 17%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">10%</td>
</tr>
</div>
</table>
</td>
</tr>
</div>
<div class="q1" >
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="20%">Negative comments about me might be being put around </td>
<td width="15%"align="center"> <label class="choice2">
<input id="Check2" name="field_Payment2" type="radio" value="rarely2" class="required" onclick="toggle('show','mytext2');">
Rarely</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="Paypal2" name="field_Payment2" type="radio" value="monthly2" class="required" onclick="toggle('show,'mytext2');">
Once a month</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="weekly2" name="field_Payment2" type="radio" value="weekly2" class="required" onclick="toggle('show','mytext2');">
Once a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="several2" name="field_Payment2" type="radio" value="several2" class="required" onclick="toggle('show','mytext2');">
Several times a week</label></td>
&nbsp
<td width="15%"align="center"> <label class="choice2">
<input id="daily2" name="field_Payment2" type="radio" value="daily2" class="required" onclick="toggle('show','mytext2');">
Once a day</label></td>
</tr>
</table>
<div class="q1" style="display:none" id="mytext2">
<table>
<table width="100%" border="0" cellpadding="1" cellspacing="0">
<tr>
<td width="20%">Our survey said:</td>
<td width="15%" align="center"> 35%</td>
<td width="15%" align="center"> 24%</td>
<td width="15%" align="center">21%</td>
<td width="15%" align="center">14%</td>
<td width="15%" align="center">7%</td>
</tr>
</table>
</div>
</body>

jmrker
10-10-2012, 03:47 PM
In your post #12, the function does not match the recommended version in post #13.
Specifically show vs. 'show' and divid vs. 'divid'

xelawho
10-10-2012, 03:51 PM
... and block vs 'block'...

dp76
10-10-2012, 03:54 PM
thanks so much for your help...just one question. My book on Javascript saya it does not really matter whether " are used or '. But it did in this case. Why was this? Was it because I missed a closing ' ?

xelawho
10-10-2012, 04:06 PM
no, it doesn't matter. Well, it does it you are nesting them in a string, but that's another question. What mattered here was that you were using them when you shouldn't have been and not when you should have.

Compare your function:


function toggle(value,divid){
if(value==show) { document.getElementById('divid').style.display=block; }
else { document.getElementById('divid').style.display=none; }
}

to mine:

function toggle(value,divid){
if(value=="show") { document.getElementById(divid).style.display="block"; }
else { document.getElementById(divid).style.display="none"; }
}
which would have worked equally well if it had been:


function toggle(value,divid){
if(value=='show') { document.getElementById(divid).style.display='block'; }
else { document.getElementById(divid).style.display='none'; }
}

or


function toggle(value,divid){
if(value=='show') { document.getElementById(divid).style.display="block"; }
else { document.getElementById(divid).style.display='none'; }
}

or any similar permutation :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum