Kunkka Posted May 31, 2009 Share Posted May 31, 2009 i want to hide one text field in form when i select a specific item in the combo box. im creating a online mcq paper. so when in the registration process i have put a combo box to select either lecture or student. so if user logs in and selects lecture. they should get extra text field. which others not getting. can someone help me Link to comment https://forums.phpfreaks.com/topic/160332-how-2-hide-one-text-field-in-a-form-when-you-select-a-specific-item-in-combo-box/ Share on other sites More sharing options...
YourNameHere Posted May 31, 2009 Share Posted May 31, 2009 This can be done easier with JavaScript. I would suggest checking out the jQuery JavaScript Library. It simplifies the everyday, mundane tasks usually done in JS. It also makes it a lot easier to learn JS if you dont already know it. Here is the Jquery website. Link to comment https://forums.phpfreaks.com/topic/160332-how-2-hide-one-text-field-in-a-form-when-you-select-a-specific-item-in-combo-box/#findComment-846069 Share on other sites More sharing options...
Ken2k7 Posted May 31, 2009 Share Posted May 31, 2009 It doesn't make it easier to learn JavaScript. You'll be surprised how many people know jQuery and can do almost anything in jQuery, but without it, they wouldn't know a thing in JavaScript. Sad really. Link to comment https://forums.phpfreaks.com/topic/160332-how-2-hide-one-text-field-in-a-form-when-you-select-a-specific-item-in-combo-box/#findComment-846073 Share on other sites More sharing options...
YourNameHere Posted May 31, 2009 Share Posted May 31, 2009 It doesn't make it easier to learn JavaScript. You're right, I stand corrected. Link to comment https://forums.phpfreaks.com/topic/160332-how-2-hide-one-text-field-in-a-form-when-you-select-a-specific-item-in-combo-box/#findComment-846075 Share on other sites More sharing options...
Kunkka Posted May 31, 2009 Author Share Posted May 31, 2009 can someone provide me with the code. how to do it Link to comment https://forums.phpfreaks.com/topic/160332-how-2-hide-one-text-field-in-a-form-when-you-select-a-specific-item-in-combo-box/#findComment-846142 Share on other sites More sharing options...
anupamsaha Posted May 31, 2009 Share Posted May 31, 2009 can someone provide me with the code. how to do it The code: <html> <head> <title>Sample</title> <style type="text/css"> <!-- #idName { display: block; } --> </style> <script type="text/javascript"> <!-- function doToggleTextBox(objSelect, theId) { var obj = document.getElementById(theId); if ( objSelect.value == '2' ) { obj.style.display = 'none'; } else { obj.style.display = 'block'; } } //--> </script> </head> <body> <form id="idForm" name="fromReg" method="post" action="register.php"> <select name="items" onChange="javascript:doToggleTextBox(this, 'idName')"> <option value="1">Item 1</option> <option value="2">Item 2</option> </select> <br /> <div id="idName"><label>Enter name: <input type="text" id="Name" /></label><br /></div> <div id="idSubject"><label>Enter subject: <input type="text" id="Subject" /></label><br /></div> </form> </body> </html> The idea in the above code is, on selection of "Item 2" from the select box, the line, "Enter name" will be hidden. Does it help? Link to comment https://forums.phpfreaks.com/topic/160332-how-2-hide-one-text-field-in-a-form-when-you-select-a-specific-item-in-combo-box/#findComment-846301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.