Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Oct 2012
    Location
    VA,USA
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Angry How to have two "other" options on the same page with different text box’s ?

    Hello!!
    I am trying to make a survey with a "zippcode" and "how far do you drive?' drop down menus with "other" options with a text box with each one.
    The Zippcode:
    Code:
    *Zip Code:  
    <script type="text/javascript">
      function showfield(name){
        if(name=='Other')document.getElementById('zipcode2').style.display="block";
        else document.getElementById('zipcode2').style.display="none";
      }
     
     function hidefield() {
     document.getElementById('zipcode2').style.display='none';
     }
      </script>
     
      <body onload="hidefield()">
     
      <select name="zipcode" id="zipcode" onchange="showfield(this.options[this.selectedIndex].value)">
      <option selected="22408">22408</option>
      <option value="22407">22407</option>
      <option value="22406">22406</option>
      <option value="22405">22405</option>
      <option value="22404">22404</option>
      <option value="22403">22403</option>
      <option value="22402">22402</option>
      <option value="22401">22401</option>
      <option value="22430">22430</option>
      <option value="22446">22446</option>
      <option value="22471">22471</option>
      <option value="22538">22538</option>
      <option value="22553">22553</option>
      <option value="22555">22555</option>
      <option value="22565">22565</option>
      <option value="22580">22580</option>
      <option value="Other">Other</option>
      </select>
      <div id="zipcode2">If Other: <input type="text" name="other" /></div>
    The mile code:

    Code:
    <script type="text/javascript">
      function showfield(name){
        if(name=='Othermiles')document.getElementById('miles2').style.display="block";
        else document.getElementById('miles2').style.display="none";
      }
     
     function hidefield() {
     document.getElementById('miles2').style.display='none';
     }
      </script>
     
      <body onload="hidefield()">
     
      <select name="miles" id="miles" onchange="showfield(this.options[this.selectedIndex].value)">
    <option value = "2 Miles">2 Miles</option>
    <option value = "4 Miles">4 Miles</option>
    <option value = "5 Miles">5 Miles</option>
    <option value = "6 Miles">6 Miles</option>
    <option value = "8 Miles">8 Miles</option>
    <option value = "10 Miles">10 Miles</option>
    <option value = "15 Miles">15 Miles</option>
    <option value = "20 Miles">20 Miles</option>
    <option value="Othermiles">Other</option>
      </select> 
     <div id="miles2">If Other: <input type="text" name="Other2" /></div>
    Please help!! Thank you very much in advance!! If you have any questions please ask.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,098
    Thanks
    23
    Thanked 594 Times in 593 Posts
    Help with what? what are you having problems with? Oh read the title dummy
    I'd put what you have in a form and add the next two things to the form N.P.
    I think you should show us what you mean by ""other" options with a text box with each one."

    Why use js for this
    Code:
    function hidefield() {
      document.getElementById('miles2').style.display='none';
    }
    </script>
    <body onload="hidefield()">
    When css will do it.
    Code:
    #miles2{
      display:none;
    }
    Last edited by sunfighter; 10-11-2012 at 04:51 PM. Reason: read title after commenting

  • #3
    New Coder
    Join Date
    Oct 2012
    Location
    VA,USA
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have started to stop using css except for the main layout of the page.
    Thanks though!

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,098
    Thanks
    23
    Thanked 594 Times in 593 Posts
    That's a bad decision. Did you get the
    "other" options with a text box with each one
    done on your own? If not post an example of the problem.

  • #5
    New Coder
    Join Date
    Oct 2012
    Location
    VA,USA
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This is the code i am having problems with.

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <script type="text/javascript">
      function showfield(name){
        if(name=='Other')document.getElementById('zipcode2').style.display="block";
        else document.getElementById('zipcode2').style.display="none";
      }
     
     function hidefield() {
     document.getElementById('zipcode2').style.display='none';
     }
      </script>
     
      <body onload="hidefield()">
     
      <select name="zipcode" id="zipcode" onchange="showfield(this.options[this.selectedIndex].value)">
      <option selected="22408">22408</option>
      <option value="22407">22407</option>
      <option value="22406">22406</option>
      <option value="22405">22405</option>
      <option value="22404">22404</option>
      <option value="22403">22403</option>
      <option value="22402">22402</option>
      <option value="22401">22401</option>
      <option value="22430">22430</option>
      <option value="22446">22446</option>
      <option value="22471">22471</option>
      <option value="22538">22538</option>
      <option value="22553">22553</option>
      <option value="22555">22555</option>
      <option value="22565">22565</option>
      <option value="22580">22580</option>
      <option value="Other">Other</option>
      </select>
      <div id="zipcode2">If Other: <input type="text" name="other" /></div>
    
    
    
    <font size="5px">How many miles do you drive to here:</font><br/>
    
    <script type="text/javascript">
      function showfield(name){
        if(name=='Othermiles')document.getElementById('miles2').style.display="block";
        else document.getElementById('miles2').style.display="none";
      }
     
     function hidefield() {
     document.getElementById('miles2').style.display='none';
     }
      </script>
     
      <body onload="hidefield()">
     
      <select name="miles" id="miles" onchange="showfield(this.options[this.selectedIndex].value)">
    <option value = "2 Miles">2 Miles</option>
    <option value = "4 Miles">4 Miles</option>
    <option value = "5 Miles">5 Miles</option>
    <option value = "6 Miles">6 Miles</option>
    <option value = "8 Miles">8 Miles</option>
    <option value = "10 Miles">10 Miles</option>
    <option value = "15 Miles">15 Miles</option>
    <option value = "20 Miles">20 Miles</option>
    <option value="Othermiles">Other</option>
      </select> 
     <div id="miles2">If Other: <input type="text" name="Other2" /></div>
    
    </body>
    </html>

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,098
    Thanks
    23
    Thanked 594 Times in 593 Posts
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <style type="text/css">
    body
    {
      font-size: x-large;
    }
    .smallertxt
    {
      font-size:large;
    }
    #miles2{
      visibility:hidden;
    }
    #zipcode2{
      visibility: hidden;
    }
    </style>
    </head>
    
    <body>
    What is your zip code:<br>
    <select name="zipcode" id="zipcode" onchange="document.getElementById('zipcode2').style.visibility = 'visible';">
    	<option value="22408" selected="selected">22408</option>
    	<option value="22407">22407</option>
    	<option value="22406">22406</option>
    	<option value="22405">22405</option>
    	<option value="22404">22404</option>
    	<option value="22403">22403</option>
    	<option value="22402">22402</option>
    	<option value="22401">22401</option>
    	<option value="22430">22430</option>
    	<option value="22446">22446</option>
    	<option value="22471">22471</option>
    	<option value="22538">22538</option>
    	<option value="22553">22553</option>
    	<option value="22555">22555</option>
    	<option value="22565">22565</option>
    	<option value="22580">22580</option>
    	<option value="Other">Other</option>
    </select>
    <div id="zipcode2" class="smallertxt">If Other, enter the zip: <input type="text" name="other"></div><br>
    
    How many miles do you drive to here:<br>
    <select name="miles" id="miles" onchange="document.getElementById('miles2').style.visibility = 'visible';">
    	<option value = "2 Miles" selected="selected">2 Miles</option>
    	<option value = "4 Miles">4 Miles</option>
    	<option value = "5 Miles">5 Miles</option>
    	<option value = "6 Miles">6 Miles</option>
    	<option value = "8 Miles">8 Miles</option>
    	<option value = "10 Miles">10 Miles</option>
    	<option value = "15 Miles">15 Miles</option>
    	<option value = "20 Miles">20 Miles</option>
    	<option value="Othermiles">Other</option>
    </select>
    <div id="miles2" class="smallertxt">If Other, enter amount driven: <input type="text" name="Other2" /></div>
    
    </body>
    </html>

  • #7
    New Coder
    Join Date
    Oct 2012
    Location
    VA,USA
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The code works very well!! I was wondering if the text box can only come up if the "other" option is selected in the menu?

    bigcoder

  • #8
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,098
    Thanks
    23
    Thanked 594 Times in 593 Posts
    Sorry, I was trying so hard to get rid of the javascript section that I didn't check for that. Javascript section back.

    Shame on you for not just correcting this.

    Code:
    
    <!DOCTYPE html>
    <html>
    <head>
    <style type="text/css">
    body
    {
      font-size: x-large;
    }
    .smallertxt
    {
      font-size:large;
    }
    #miles2{
      visibility:hidden;
    }
    #zipcode2{
      visibility: hidden;
    }
    </style>
    <script type="text/javascript">
    function other_zip(choice)
    {
    	if(choice == "Other") document.getElementById('zipcode2').style.visibility = 'visible';
    }
    function other_miles(choice)
    {
    	if(choice == "Othermiles") document.getElementById('miles2').style.visibility = 'visible';
    }
    </script>
    </head>
    
    <body>
    What is your zip code:<br>
    <select name="zipcode" id="zipcode" onchange="other_zip(this.options[this.selectedIndex].value);">
    	<option value="22408" selected="selected">22408</option>
    	<option value="22407">22407</option>
    	<option value="22406">22406</option>
    	<option value="22405">22405</option>
    	<option value="22404">22404</option>
    	<option value="22403">22403</option>
    	<option value="22402">22402</option>
    	<option value="22401">22401</option>
    	<option value="22430">22430</option>
    	<option value="22446">22446</option>
    	<option value="22471">22471</option>
    	<option value="22538">22538</option>
    	<option value="22553">22553</option>
    	<option value="22555">22555</option>
    	<option value="22565">22565</option>
    	<option value="22580">22580</option>
    	<option value="Other">Other</option>
    </select>
    <div id="zipcode2" class="smallertxt">If Other, enter the zip: <input type="text" name="other"></div><br>
    
    How many miles do you drive to here:<br>
    <select name="miles" id="miles" onchange="other_miles(this.options[this.selectedIndex].value);">
    	<option value = "2 Miles" selected="selected">2 Miles</option>
    	<option value = "4 Miles">4 Miles</option>
    	<option value = "5 Miles">5 Miles</option>
    	<option value = "6 Miles">6 Miles</option>
    	<option value = "8 Miles">8 Miles</option>
    	<option value = "10 Miles">10 Miles</option>
    	<option value = "15 Miles">15 Miles</option>
    	<option value = "20 Miles">20 Miles</option>
    	<option value="Othermiles">Other</option>
    </select>
    <div id="miles2" class="smallertxt">If Other, enter amount driven: <input type="text" name="Other2"></div>
    
    </body>
    </html>

  • Users who have thanked sunfighter for this post:

    bigcoder (10-13-2012)

  • #9
    New Coder
    Join Date
    Oct 2012
    Location
    VA,USA
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I very much appreciate you help, sunfighter!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •