elmas156 Posted April 22, 2011 Share Posted April 22, 2011 I know that there is a way to this with javascript, but I don't know how it would work. I am much more familiar with php so I figured I would ask here to see if anyone might have a good php solution. I'm trying to have a form text field display depending on whether or not the user checks a specific box, but I'm not sure where to start. I've searched around but I didn't find anything that would help. Basically I want to have a checkbox that asks if the user would like to link their account to an email address. If the checkbox is selected, a textbox will then appear on the page for them to enter an email address. Can anyone point me in the right direction on where to start? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/234399-display-form-field-depending-on-checkbox-value/ Share on other sites More sharing options...
mens Posted April 22, 2011 Share Posted April 22, 2011 Using Javascript would be your best solution, and less time consuming on your part. By adding an onclick property to the checkbox, you can alter the display properties of a specific input element causing it top appear. The back-end of this, would be simple: if the specific checkbox is selected validate the input element - else, don't. This can be done with PHP, sure. But the user will need to submit the form, and you need to validate it and generate the HTML for the input element; and then output it... again. Quote Link to comment https://forums.phpfreaks.com/topic/234399-display-form-field-depending-on-checkbox-value/#findComment-1204700 Share on other sites More sharing options...
elmas156 Posted April 22, 2011 Author Share Posted April 22, 2011 Thanks for the reply. Do you know of anywhere I can find a good tutorial on how to do this? I don't use javascript much at all and I am very limited in my knowledge in it. Thanks again for your help. Quote Link to comment https://forums.phpfreaks.com/topic/234399-display-form-field-depending-on-checkbox-value/#findComment-1204705 Share on other sites More sharing options...
mens Posted April 22, 2011 Share Posted April 22, 2011 I can't think of any tutorials for this specific task, but I would suggest reading up on jQuery. It makes working with Javascript much easier. Here's a guide on checkbox/radio manipulation with jQuery: http://www.techiegyan.com/2008/07/09/using-jquery-check-boxes-and-radio-buttons/ Quote Link to comment https://forums.phpfreaks.com/topic/234399-display-form-field-depending-on-checkbox-value/#findComment-1204707 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.