Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/252759-contact-form-with-user-inputted-subject/
Share on other sites

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>

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.