• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

Show New fields if one radio button option is selected

I have a very simple form that writes to a database. It asks -do you rent or own?
if they rent, I need to ask for Landlord Information

I don't want to show the fields of the form unless they say they rent and I still need it to save to the database...
<table><tr>  <td>Do you?  </td>
              <td>
<?PHP echo"<input type=\"radio\" name=\"Res1Rent\" value=\"Rent\" checked=true> Rent
<input type=\"radio\" name=\"Res1Rent\" value=\"Own\"> Own\n";?>
 </td>
            </tr>
        THESE FIELDS WON"T SHOW UNLESS RENT OPTION IS SELECTED ABOVE

<tr><td colspan="4">Please list Landlords Information</td></tr><tr><td>Name:</td><td><?PHP echo "<input type=\"text\" name=\"Landlord1\" value=\"$Landlord1\">\n";?></td><td>Address</td><td><?PHP echo "<input type=\"text\" name=\"LL1Address\" value=\"$LL1Address\" />\n";?></td></tr><tr><td>Phone</td><td><?PHP echo "<input type=\"text\" name=\"LL1Phone\" value=\"$LL1Phone\"/>\n";?></td><td></td></tr></table>

Open in new window

0
katlees
Asked:
katlees
1 Solution
 
CEHJCommented:
Not a Java question is it?
0
 
katleesAuthor Commented:
Sorry, didn't see that I hit that... No, it isn't.
0
 
for_yanCommented:
Does this have anything to do with Java Progarmming Language?
I think this is about PHP and  JavaScript.
0
 
owaisyahyaCommented:
Disable the conditional fields by default and enable it (using javascript) when user selects  the option.


    <script type="text/javascript">
        function show(id,bool)
        {
            var obj=document.getElementById(id);
            if(bool)
            {
                obj.style.display='';
            }
            else
            {
                obj.style.display='none';
            }
        }
    </script>

        Rent:<input id="Radio1" type="radio" onclick="show('div_hidden',true)" name="grp1" />&nbsp;&nbsp;&nbsp;&nbsp;Owned:<input id="Radio2" type="radio" onclick="show('div_hidden',false)" name="grp1"/><br />
        <div id="div_hidden" style="display:none">Landlord Name:<input id="Text1" type="text" /> </div>

Open in new window


0
 
katleesAuthor Commented:
PERFECT! Thank you
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now