It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

show div with drop down list

show div with drop down list

Postby yaymeq on Tue Mar 18, 2008 12:17 am

I've got a form and it has a drop down list like so :
Code: Select all
<select name="Hearaboutus"  onchange="change()" id="choose">
         <option value="pleasechoose">Please choose</option>
         <option value="Friend">Friend</option>
         <option value="Real estate agent"> Real estate agent</option>
         <option value="Search engine"> Search engine</option>
         <option value="Sign"> Sign</option>
         <option value="Flyer"> Flyer</option>
         <option value="Business card"> Business card</option>
         <option value="Direct mail"> Direct mail</option>
         <option value="Other"> Other </option></select>


If they select "other" I want:
Code: Select all
   <tr valign="top" id="ifother">
      <td align="right" >If other please explain.</td>
      <td align="left"><input type="text" name="whoisother" value="" maxlength="100" size="30"></td>
   </tr>

to appear. I've got some Idea of how to do this ... for example:
Code: Select all
<script type="text/javascript">

window.onload = function()
{                                            //line51
document.getElementById("change").style.display='none';
}

function change()
{
   switch (document.getElementById("choose").value)
   {
      case "Friend":
     document.getElementById("ifother").style.display='none'
      break;
      case "Real estate agent":
     document.getElementById("ifother").style.display='none'
      break;
      case "Sign":
     document.getElementById("ifother").style.display='none'
      break;
      case "Other":
     document.getElementById("ifother").style.display=''
      break;
   }
}
obviously with the rest of the cases as well, but it's not working. The problem is that when I do this piece of code by itself it says an object is required on line 51 which I've marked. I don't understand it.
yaymeq
 
Posts: 2
Joined: Mon Mar 17, 2008 11:43 pm

Postby rangana on Tue Mar 18, 2008 2:12 am

Hi there yaymeq,
We've met again, the code looks familiar isn't it? Lol. :)

Anyway that error is brought by:
Code: Select all
window.onload = function()
{
document.getElementById("change").style.display='none';
}


Note that you don't have an element that has an id change in your page. ;)

Hope it help :)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby yaymeq on Tue Mar 18, 2008 2:24 am

Ah and see I went elsewhere because I didn't want to be a bother always asking the same things. Well, I actually got it to work on my own! I don't remember what I did ... I tried many different combinations and the same one that didn't work the first time worked the second so who knows ... Anyway, thanks for all the help. :)
yaymeq
 
Posts: 2
Joined: Mon Mar 17, 2008 11:43 pm


Who is online

Users browsing this forum: No registered users and 7 guests