Chained checkbox
Moderator: General Moderators
Chained checkbox
I would like to have a checkbox, if selected it will show a selection box.
Unchecked the selection box disappears and the values of the selection box are cleared also.
Possible?
Unchecked the selection box disappears and the values of the selection box are cleared also.
Possible?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Ok i have this javascript code here in my check box:
I have this code here for my selection box:
The selection box is invisible. However, when I hit the checkbox it does not appear?
Code: Select all
onclick="javascript:document.new_request.l_followup_period.style = '';"Code: Select all
<select name="l_followup_period" class="orderInput" style="display: none;">Code: Select all
onclick="javascript:document.new_request.l_followup_period.style.display = 'block';"I have tried this but it is not working:
Code: Select all
onclick="this.form.elements['l_followup_period'].display = this.checked ? '' : 'none';"Code: Select all
function updateBox(object) {
if(object.checked)
document.new_request.l_followup_period.style.display = 'block';
else
document.new_request.l_followup_period.style.display = 'none';
}
..................
onclick="updateBox(this);"- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
<tr>
<td class="blueBar"> </td>
<script type="JavaScript">
function updateBox(object) {
if(object.checked)
document.new_request.l_followup_period.style.display = '';
else
document.new_request.l_followup_period.style.display = 'none';
}
</script>
<td height="33" class="lightblueBar"> <input type="checkbox" name="l_followup" class="orderInput" onclick="updateBox(this);"><?php if($_POST["l_followup"]) { echo " checked"; } ?> <b>Is this a laundromat follow up survey?</b>
<select name="l_followup_period" class="orderInput" style="display: none;">
<option value="3"<?php if($_POST["submit"] && $_POST["l_followup_period"] == "3") { echo "selected"; } if($_SESSION["l_followup_period"] == "3") { echo " selected"; } ?>>Every Three Months</option>
<option value="6"<?php if($_POST["submit"] && $_POST["l_followup_period"] == "6") { echo "selected"; } if($_SESSION["l_followup_period"] == "6") { echo " selected"; } ?>>Every Six Months</option>
<option value="9"<?php if($_POST["submit"] && $_POST["l_followup_period"] == "9") { echo "selected"; } if($_SESSION["l_followup_period"] == "9") { echo " selected"; } ?>>Every Nine Months</option>
<option value="12"<?php if($_POST["submit"] && $_POST["l_followup_period"] == "12") { echo "selected"; } if($_SESSION["l_followup_period"] == "12") { echo " selected"; } ?>>Annually</option>
</select>
</td>
</tr>It is:
You have other errors:
1. your echo of "checked" is outside the check box tag;
2. there is no white space between your echo of "selected" and "value" in the option tags;
3. you should use "if ... elseif" instead of two "if"s for echoing "selected"
4. you have not implemented the trigger in the JS function.
5. use document.getElementById()
Code: Select all
<script language="JavaScript">1. your echo of "checked" is outside the check box tag;
2. there is no white space between your echo of "selected" and "value" in the option tags;
3. you should use "if ... elseif" instead of two "if"s for echoing "selected"
4. you have not implemented the trigger in the JS function.
5. use document.getElementById()
There are 10 types of people in this world, those who understand binary and those who don't