Page 1 of 1

program a set of radio buttons to automatically fill in

Posted: Thu Nov 17, 2011 3:18 pm
by pmarley2
hi all, i have the following form:

Code: Select all

    <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.

thanks!
~p

Re: program a set of radio buttons to automatically fill in

Posted: Tue Nov 22, 2011 1:28 pm
by manohoo
use Javascript

Re: program a set of radio buttons to automatically fill in

Posted: Tue Nov 22, 2011 1:48 pm
by maxx99
http://www.tizag.com/javascriptT/javasc ... ntbyid.php
http://www.hscripts.com/tutorials/javas ... events.php
This should put you on the right track :) first try it on something simple

Re: program a set of radio buttons to automatically fill in

Posted: Tue Nov 22, 2011 3:01 pm
by califdon
I would suggest that you re-think your form. It would be much simpler, not only to program, but for the user to fill in, if you just asked "What is the maximum you would pay for 'x'?", then have a series of radio buttons, like $1, $2, $3, etc. It would also make the code for using the data much simpler.