Page 1 of 1

Dynamic Drop Down Menu

Posted: Thu Jan 22, 2009 2:56 am
by azhan
hey guys,

hear this situation

A drop down menu with these option:

1) Paedriatic
2) Orthopaedic
3) ICU
4) Others

is there any code that once the user choose "Others", a new blank field will appear for the user to key in the value at that very moment.

Similar like when a user choose an option on the drop down menu, the option will lead directy to other page. But what im trying to do is when a user choose the last option, the new blank input is appear for user to key in the "Other" field value.

i guess it involves javascript isnt it?

does anyone care to share?

thanks

azhan

Re: Dynamic Drop Down Menu

Posted: Thu Jan 22, 2009 3:15 am
by papa
Give it a try using google and then I can help you tuning the code.

Re: Dynamic Drop Down Menu

Posted: Thu Jan 22, 2009 3:38 am
by mattpointblank

Re: Dynamic Drop Down Menu

Posted: Wed Feb 04, 2009 3:14 pm
by tat
Hi, I have a slightly different issue
I created a dynamic drop down box that extract values from a column in a mysql database. But I want a first drop down that has all 26 letters of the alphabet, based on the result of the first drop down, the dynamic drop down should be populated.
For the first drop down, I created a non dynamic drop down but not sure how to code so that the result is used to populate the dynamic drop down...

Re: Dynamic Drop Down Menu

Posted: Wed Feb 04, 2009 3:31 pm
by Skoalbasher
AJAX. Read up on AJAX and dynamic dropdown. Mix of Javscript and PHP/ASP/whatever server side script...

Re: Dynamic Drop Down Menu

Posted: Wed Feb 04, 2009 7:12 pm
by tat
Are you kidding me....you made it sound very complicated! any guidance which chapters, I should read about ajax, javascript Texan??

Re: Dynamic Drop Down Menu

Posted: Wed Feb 04, 2009 10:01 pm
by Skoalbasher
tat wrote:Are you kidding me....you made it sound very complicated! any guidance which chapters, I should read about ajax, javascript Texan??
Ok sorry, I actually read your post incorrectly. This is just Javascript and HTML. This really doesn't belong in this part of the forum I don't think, but here ya go.

Add this to the top of your page, in between the <HEAD></HEAD> tags.

Code: Select all

 
<SCRIPT LANGUAGE="JavaScript"> 
document.getElementById("oth").visibility='hidden';
 
function doWork(idnum){
  // check to see if user selected the 4th option
  if(idnum == 4){
    document.getElementById("oth").visibility='visible';
  }
  else {
    document.getElementById("oth").visibility='hidden';
    // uncomment the line below to clear the "other" textbox if another option is checked
    //document.getElementById("other").value = ""; 
  }
}
</script>
 

Code: Select all

 
<select name="medstuff" id="medstuff" onchange="doWork(this.value)">  <!--this calls javascript function-->
  <option value="1">Paedriatic</option>
  <option value="2">Orthopaedic</option>
  <option value="3">ICU</option>
  <option value="4">Others</option>
</select>
 
<!--------------- Add this to where you want your text box to come up------->
<div id="oth">
<input type="text" name="other" id="other" value="">
</div>
 
I already had the javascript written from something I'm working on right now.

Re: Dynamic Drop Down Menu

Posted: Wed Feb 04, 2009 10:24 pm
by bigbstanley
definitely javascript on that one. Look up a hide/show function or check out jQuery - tons of examples of common javascript for you to play with and implement into your dropdown.

Re: Dynamic Drop Down Menu

Posted: Thu Feb 05, 2009 12:30 pm
by tat
:D Thanks guys. Sorry for not posting on the right part of the forum.