Zergman Posted October 3, 2008 Share Posted October 3, 2008 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 More sharing options...
ultratek Posted October 3, 2008 Share Posted October 3, 2008 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 https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656553 Share on other sites More sharing options...
Zergman Posted October 3, 2008 Author Share Posted October 3, 2008 Thanks for the reply, not sure on this myself. Your pretty much looking at all the code im using for this. Not sure how I could do the if else for this. Do you have an example? Link to comment https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656558 Share on other sites More sharing options...
ultratek Posted October 3, 2008 Share Posted October 3, 2008 i'll see what i can come up with...just give me lil while to go over some code in my book Link to comment https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656560 Share on other sites More sharing options...
Zergman Posted October 3, 2008 Author Share Posted October 3, 2008 rock on, thanks for the help Link to comment https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656575 Share on other sites More sharing options...
ultratek Posted October 3, 2008 Share Posted October 3, 2008 well so far i tried using the html code you posted with the checkbox behaviors...and i have no menus popping up Link to comment https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656600 Share on other sites More sharing options...
ultratek Posted October 3, 2008 Share Posted October 3, 2008 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 More sharing options...
Zergman Posted October 3, 2008 Author Share Posted October 3, 2008 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 More sharing options...
ultratek Posted October 3, 2008 Share Posted October 3, 2008 yea it is still fresh... i cant test it until i get the drop down menus working.... so i dont know what i should change yet Link to comment https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656628 Share on other sites More sharing options...
ultratek Posted October 3, 2008 Share Posted October 3, 2008 how do i make drop down menus for the check boxes on my own...? Link to comment https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656631 Share on other sites More sharing options...
Flames Posted October 3, 2008 Share Posted October 3, 2008 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 More sharing options...
Zergman Posted October 3, 2008 Author Share Posted October 3, 2008 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 More sharing options...
ultratek Posted October 3, 2008 Share Posted October 3, 2008 hmm for some reason they are not triggering a drop down menu when i try .... Link to comment https://forums.phpfreaks.com/topic/126932-form-control-help/#findComment-656642 Share on other sites More sharing options...
Zergman Posted October 3, 2008 Author Share Posted October 3, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.