program a set of radio buttons to automatically fill in

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pmarley2
Forum Newbie
Posts: 6
Joined: Thu Nov 17, 2011 6:29 am

program a set of radio buttons to automatically fill in

Post 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
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

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

Post by manohoo »

use Javascript
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

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

Post 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
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

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

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