MadFly Posted December 8, 2011 Share Posted December 8, 2011 Hi I would like to add a subject <select> field to my contact form, where the user can select from certain subjucts or enter his/her own subject. What I have so far is: <select name="client_subject"> <option value="">Select...</option> <option value="Option 1">Option 1</option> <option value="Option 2">Option 2</option> <option value="Option 3">Option 3</option> <option value="Option 4">Option 4</option> <option value="Custom Subject"><input type="text" value="" size="40"></option> </select> This is only the select part of the form. When I use it like this, I get the input text field outside the dropdown list. I would like it to be inside the dropdown list as an option, and once selected, give you the input text field where you can enter your own custom subject to be added to the email that will be sent. Quote Link to comment https://forums.phpfreaks.com/topic/252759-contact-form-with-user-inputted-subject/ Share on other sites More sharing options...
kney Posted December 8, 2011 Share Posted December 8, 2011 Not sure if this can be done with php but.. <script type="text/javascript"> function custom_select_val(select_elm, prompt_text){ var val = prompt(prompt_text, ''); var option = document.createElement('option'); option.setAttribute('value', val); option.innerHTML = val; option.selected = true; select_elm.appendChild(option); }; </script> <select name="thing" onchange="if(this.value=='!') custom_select_val(this, 'Enter your custom value.')"> <option value="static1">static item 1</option> <option value="static2">static item 2</option> <option value="static3">static item 3</option> <option value="!">[specify...]</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/252759-contact-form-with-user-inputted-subject/#findComment-1295798 Share on other sites More sharing options...
MadFly Posted December 8, 2011 Author Share Posted December 8, 2011 Excellent! That worked like a charm Not sure if this can be done with php but.. The form itself is a normal html form, but I think it uses 90% php to process everything and so on. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/252759-contact-form-with-user-inputted-subject/#findComment-1295818 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.