Help with php contact / application form

5 replies
Can anyone help me with this. I am creating a contact form in php. My client wants to have an option where, if the customer selects 'less than 3 yrs' it brings up another box below than they can input their previous address.

HTML Code:
<label>* Time At Address: <?php form_error('Time_At_Address');?></label>
    <select name="Time_At_Address_YRS" class="dropdown2">
        <option selected="selected" value="">Please select...</option>
      	<option value="less than 3yrs">less than 3yrs</option>
      	<option value="4yrs">4yrs</option>
      	<option value="5yrs">5yrs</option>
      	<option value="6yrs">6yrs</option>
      	<option value="7yrs">7yrs</option>
      	<option value="8yrs">8yrs</option>
      	<option value="9yrs">9yrs</option>
      	<option value="10yrs">10yrs</option>
      	<option value="11yrs">11yrs</option>
    </select>
This is the box that I want to appear if the customer selects 'less than 3yrs'
HTML Code:
<label>* Previous Address: <?php form_error('Previous_Address');?></label>
    <input name="Previous_Address" type="text" class="input" />

<label>* Previous Post Code: <?php form_error('Previous_Post_Code');?></label>
    <input name="Previous_Post_Code" type="text" class="input" />
#application #contact #form #php
  • Profile picture of the author jlandells
    Probably the easiest way is to have the code there all the time but wrap it in a div and use CSS to hide it. You should then be able to easily change the visibility of that element using a small piece of embedded Javascript.

    Hope that helps,
    -John.
    {{ DiscussionBoard.errors[6540943].message }}
  • Profile picture of the author djdclarke
    There are a few ways to do it; and indeed if you use jQuery a less ugly way - I've coded up some quick examples for you:

    trafficcake.com/outreach/code/3years/jquery.html
    trafficcake.com/outreach/code/3years/index.html

    First with jQuery and 2nd without it. Hope this helps

    ^Dan
    {{ DiscussionBoard.errors[6541363].message }}
    • Profile picture of the author Justin B
      djdclarke You are a star!!!

      I forgot to mention that after the years, I also have months options aswell.

      Your code works if just using years, but how do I remove the months if 'less than 3yrs' is selected using the html version?


      This is my current code:

      HTML Code:
       <label>* Time At Address: </label>
          <select name="Time_At_Address_YRS" class="dropdown2">
              <option selected="selected" value="">Please select...</option>
            	<option value="less than 3yrs">less than 3yrs</option>
            	<option value="4yrs">4yrs</option>
            	<option value="4yrs">4yrs</option>
            	<option value="5yrs">5yrs</option>
            	<option value="6yrs">6yrs</option>
            	<option value="7yrs">7yrs</option>
            	<option value="8yrs">8yrs</option>
            	<option value="9yrs">9yrs</option>
            	<option value="10yrs">10yrs</option>
            	<option value="11yrs">11yrs</option>
          </select>
      
          <select name="Time_At_Address_MTHS" class="dropdown2">
              <option selected="selected" value="">Please select...</option>
            	<option value="1mth">1mth</option>
            	<option value="2mths">2mths</option>
            	<option value="3mths">3mths</option>
            	<option value="4mths">4mths</option>
            	<option value="5mths">5mths</option>
            	<option value="6mths">6mths</option>
            	<option value="7mths">7mths</option>
            	<option value="8mths">8mths</option>
            	<option value="9mths">9mths</option>
            	<option value="10mths">10mths</option>
            	<option value="11mths">11mths</option>
            	<option value="12mths">12mths</option>
          </select>
      {{ DiscussionBoard.errors[6541537].message }}
  • Profile picture of the author djdclarke
    Hey Justin,

    trafficcake.com/outreach/code/3years/jquery.html
    trafficcake.com/outreach/code/3years/index.html

    Have been updated to reflect these changes. Hope that helps -
    {{ DiscussionBoard.errors[6542447].message }}
    • Profile picture of the author Justin B
      THANKYOU SOOOOOOOO MUCH!!!! It works... :-)
      {{ DiscussionBoard.errors[6545899].message }}

Trending Topics