Dynamic Drop Down Menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azhan
Forum Commoner
Posts: 68
Joined: Fri Jun 27, 2008 6:05 am

Dynamic Drop Down Menu

Post 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
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Dynamic Drop Down Menu

Post by papa »

Give it a try using google and then I can help you tuning the code.
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: Dynamic Drop Down Menu

Post by mattpointblank »

tat
Forum Newbie
Posts: 11
Joined: Mon Feb 02, 2009 10:56 am

Re: Dynamic Drop Down Menu

Post 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...
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Dynamic Drop Down Menu

Post by Skoalbasher »

AJAX. Read up on AJAX and dynamic dropdown. Mix of Javscript and PHP/ASP/whatever server side script...
tat
Forum Newbie
Posts: 11
Joined: Mon Feb 02, 2009 10:56 am

Re: Dynamic Drop Down Menu

Post by tat »

Are you kidding me....you made it sound very complicated! any guidance which chapters, I should read about ajax, javascript Texan??
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Dynamic Drop Down Menu

Post 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.
bigbstanley
Forum Newbie
Posts: 4
Joined: Sat Mar 04, 2006 11:48 am
Location: Fort Lauderdale, FL

Re: Dynamic Drop Down Menu

Post 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.
tat
Forum Newbie
Posts: 11
Joined: Mon Feb 02, 2009 10:56 am

Re: Dynamic Drop Down Menu

Post by tat »

:D Thanks guys. Sorry for not posting on the right part of the forum.
Post Reply