Jump to content

Form Control Help


Zergman

Recommended Posts

In my entry form, I have a bunch of fields, but 2 in particular that im trying to do something different with.

 

I have 2 checkboxes that trigger a dropdown menu depending if they are checked.

 

The check boxes

Working<input type="checkbox" name="chkOther" id="chk" value="1" onclick="this.form.txtOther.style.display=(this.checked)?'inline':'none'" />
                  
Not Working<input type="checkbox" name="chkOther2" id="chk2" value="1" onclick="this.form.txtOther2.style.display=(this.checked)?'inline':'none'" /> 

 

And the dropdowns

<select name="txtOther" class="inputbox" id="txtOther" style="display:none" >
<option value="Box1">Box1</option>
<option value="Box1 Option1">Box1 Option1</option>
</select>
              

<select name="txtOther2" class="inputbox" id="txtOther2" style="display:none" >
<option value="Box 2">Box 2</option>
<option value="Box 2 Option1">Box 2 Option1</option>
</select>

 

These work great, except I only want the value of the one dropdown, not both.  Right now, If I make a selection in Box1, uncheck it, then select Box2, Box1 doesn't reset and the value stays.

 

This is hard to explain, but how can I have the dropdown reset if the other dropdown is selected?  Something to do with the checkboxes?

Link to comment
https://forums.phpfreaks.com/topic/126932-form-control-help/
Share on other sites

what i am coming up with so far looks like this:

<?php
$checkbox1 = chkother
$menu1 = txtother
if (isset($checkbox1)) {
$checkbox1 = 'txtother'
	if ($checkbox1 == 'txtother') {
	$menu1 = isset;
} elseif (checkbox1 = NULL){
$menu1 = NULL;

<table width="100%" border="0">
  <tr>
    <td>Working
    <input type="checkbox" name="chkOther" id="chk" value="1" onclick="this.form.txtOther.style.display=(this.checked)?'inline':'none'" /></td>
    <td> Working2
      <input type="checkbox" name="chkOther2" id="chk2" value="1" onclick="this.form.txtOther2.style.display=(this.checked)?'inline':'none'" /></td>
  </tr>
</table>
<select name="txtOther" class="inputbox" id="txtOther" style="display:none" >
<option value="Box1">Box1</option>
<option value="Box1 Option1">Box1 Option1</option>
</select>
              

<select name="txtOther2" class="inputbox" id="txtOther2" style="display:none" >
<option value="Box 2">Box 2</option>
<option value="Box 2 Option1">Box 2 Option1</option>
</select>
} else {
$checkbox1 = NULL;
}
?>

 

be sure to save your file with the form/checkboxes/menus as php extension

Link to comment
https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656619
Share on other sites

what i am coming up with so far looks like this:

<?php
$checkbox1 = chkother
$menu1 = txtother
if (isset($checkbox1)) {
$checkbox1 = 'txtother'
	if ($checkbox1 == 'txtother') {
	$menu1 = isset;
} elseif (checkbox1 = NULL){
$menu1 = NULL;

<table width="100%" border="0">
  <tr>
    <td>Working
    <input type="checkbox" name="chkOther" id="chk" value="1" onclick="this.form.txtOther.style.display=(this.checked)?'inline':'none'" /></td>
    <td> Working2
      <input type="checkbox" name="chkOther2" id="chk2" value="1" onclick="this.form.txtOther2.style.display=(this.checked)?'inline':'none'" /></td>
  </tr>
</table>
<select name="txtOther" class="inputbox" id="txtOther" style="display:none" >
<option value="Box1">Box1</option>
<option value="Box1 Option1">Box1 Option1</option>
</select>
              

<select name="txtOther2" class="inputbox" id="txtOther2" style="display:none" >
<option value="Box 2">Box 2</option>
<option value="Box 2 Option1">Box 2 Option1</option>
</select>
} else {
$checkbox1 = NULL;
}
?>

 

be sure to save your file with the form/checkboxes/menus as php extension

 

WOW, this went WAY over my head lol.

 

Looks like it will do what I want, except im getting "Parse error: syntax error, unexpected T_VARIABLE" on $menu1 = txtother

Link to comment
https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656626
Share on other sites

maybe you could try using some Javascript so for the check boxes have a function that occurs onChange, the function could see if the checkbox is ticked or unticked and change the drop down accordingly you'll need some codes like document.formname.fieldname.value == "", maybe have a look on the internet?

Link to comment
https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656632
Share on other sites

Heres the origional code I started with.

 

<input type="checkbox" name="chkOther" id="chk" value="1" onclick="this.form.txtOther.style.display=(this.checked)?'inline':'none'" /><label for="chk">Other</label>
<input type="text" name="txtOther" style="display:none" />

 

Thought about using radio buttons, but they act weird.

<form id="form1" name="form1" method="post" action="">
 <input type="radio" name="radio" id="radio" value="radio" onclick="this.form.box1.style.display=(this.checked)?'inline':'none'"/>
 <input type="radio" name="radio" id="radio" value="radio1" onclick="this.form.box2.style.display=(this.checked)?'inline':'none'"/>
</p>
<p>
 <input name="box1" type="text" id="box1" value="1" style="display:none"/>
 <input name="box2" type="text" id="box2" value="2" style="display:none"/>
</p>
</form>

Link to comment
https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656635
Share on other sites

Weird, heres my entire page that works on my server

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body><form action="" method="get">
Working<input type="checkbox" name="chkOther" id="chk" value="1" onclick="this.form.txtOther.style.display=(this.checked)?'inline':'none'" />
                  
Not Working<input type="checkbox" name="chkOther2" id="chk2" value="1" onclick="this.form.txtOther2.style.display=(this.checked)?'inline':'none'" /> 

<select name="txtOther" class="inputbox" id="txtOther" style="display:none" >
<option value="Box1">Box1</option>
<option value="Box1 Option1">Box1 Option1</option>
</select>
              

<select name="txtOther2" class="inputbox" id="txtOther2" style="display:none" >
<option value="Box 2">Box 2</option>
<option value="Box 2 Option1">Box 2 Option1</option>
</select>
</form>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656662
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.