...

View Full Version : program a set of radio buttons to automatically fill in



pmarley2
11-18-2011, 11:05 AM
hi all, i have the following form:



<form id="form1" name="form1" method="post" action="results.php">
<table width="680" border="0" align="center" cellpadding="5" cellspacing="5">
<tr>
<td colspan="5"><strong>How much would you pay for X? </strong></td>
</tr>
<tr>
<td width="100"><div align="center">$1</div></td>
<td width="125"><div align="center"><span class="style13">
<input name="p1" type="radio" value="yes" />
</span></div></td>
<td width="125"><div align="center">Yes</div></td>
<td width="125"><div align="center"><span class="style13">
<input name="p1" type="radio" value="no" />
</span></div></td>
<td width="125"><div align="center">No</div></td>
</tr>
<tr>
<td><div align="center">$2</div></td>
<td><div align="center"><span class="style13">
<input name="p2" type="radio" value="yes" />
</span></div></td>
<td><div align="center">Yes</div></td>
<td><div align="center"><span class="style13">
<input name="p2" type="radio" value="no" />
</span></div></td>
<td><div align="center">No</div></td>
</tr>
<tr>
<td><div align="center">$3</div></td>
<td><div align="center"><span class="style13">
<input name="p3" type="radio" value="yes" />
</span></div></td>
<td><div align="center">Yes</div></td>
<td><div align="center"><span class="style13">
<input name="p3" type="radio" value="no" />
</span></div></td>
<td><div align="center">No</div></td>
</tr>
<tr>
<td><div align="center">$4</div></td>
<td><div align="center"><span class="style13">
<input name="p4" type="radio" value="yes" />
</span></div></td>
<td><div align="center">Yes</div></td>
<td><div align="center"><span class="style13">
<input name="p4" type="radio" value="no" />
</span></div></td>
<td><div align="center">No</div></td>
</tr>
<tr>
<td><div align="center">$5</div></td>
<td><div align="center"><span class="style13">
<input name="p5" type="radio" value="yes" />
</span></div></td>
<td><div align="center">Yes</div></td>
<td><div align="center"><span class="style13">
<input name="p5" type="radio" value="no" />
</span></div></td>
<td><div align="center">No</div></td>
</tr>
</table> </form>



sorry for the lengthy code because of the table.

what i want to do is, if the user clicks No for for any input (p1 through p5), then I want all the other inputs below to automatically fill in with No as well. Similarly, if the user clicks Yes for any answer, I want all the inputs above that answer to fill in with Yes.

i think those are the only two rules i would have to program to ensure that the user provides consistent answers.

i'd also like to know how, if input 1 is a set of radio buttons, and one of them is selected, you can use that result to fill in input 2 in a certain way.

thanks

timgolding
11-18-2011, 11:14 AM
You could use javascript to change the state of any of you radio buttons. Not really a PHP question. Here's some js functions that could help http://www.somacon.com/p143.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum