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
Share on other sites

i am a noob...but you might could wrap the checkboxes and menus in an if and else condition...calling them out by assigning their ids to a variable...

i was just browsing through my book...maybe it might give you an idea...

could you post your current php code?

Link to comment
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.