Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    11
    Thanks
    5
    Thanked 0 Times in 0 Posts

    program a set of radio buttons to automatically fill in

    hi all, i have the following form:


    Code:
        <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

  • #2
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    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
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •