Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2012, 01:01 AM   PM User | #1
bigcoder
New Coder

 
Join Date: Oct 2012
Location: VA,USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
bigcoder is an unknown quantity at this point
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.
bigcoder is offline   Reply With Quote
Old 10-11-2012, 04:39 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
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
sunfighter is offline   Reply With Quote
Old 10-11-2012, 09:10 PM   PM User | #3
bigcoder
New Coder

 
Join Date: Oct 2012
Location: VA,USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
bigcoder is an unknown quantity at this point
I have started to stop using css except for the main layout of the page.
Thanks though!
bigcoder is offline   Reply With Quote
Old 10-12-2012, 01:57 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
That's a bad decision. Did you get the
Quote:
"other" options with a text box with each one
done on your own? If not post an example of the problem.
sunfighter is offline   Reply With Quote
Old 10-12-2012, 08:31 PM   PM User | #5
bigcoder
New Coder

 
Join Date: Oct 2012
Location: VA,USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
bigcoder is an unknown quantity at this point
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>
bigcoder is offline   Reply With Quote
Old 10-13-2012, 12:59 AM   PM User | #6
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
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>
sunfighter is offline   Reply With Quote
Old 10-13-2012, 02:44 AM   PM User | #7
bigcoder
New Coder

 
Join Date: Oct 2012
Location: VA,USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
bigcoder is an unknown quantity at this point
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
bigcoder is offline   Reply With Quote
Old 10-13-2012, 12:55 PM   PM User | #8
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
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>
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
bigcoder (10-13-2012)
Old 10-13-2012, 08:25 PM   PM User | #9
bigcoder
New Coder

 
Join Date: Oct 2012
Location: VA,USA
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
bigcoder is an unknown quantity at this point
I very much appreciate you help, sunfighter!!
bigcoder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:34 AM.


Advertisement
Log in to turn off these ads.