Jump to content

How Does A Drop Down Works


Panta

Recommended Posts

please i need to know how to write a script that will change the content of Department on selection of Faculty.What i mean is maybe on selection of Sciences from Faculty, the content of Department will change to Science Departments.

<form>Department:<select><option>Mechanical</option><option>Chemical</option><option>Civil</option></select><br>Faculty:<select><option>Engineering</option><option>Sciences</option><option>Law</option></select></form>

Link to comment
Share on other sites

We need to know a little bit more info before we can post anything valuable. Please tell me the following:-Is the informatie stored in html files?-Are you using a database that stores info?-Are you good with javascript?If you need a javascript that changes the page on select, please read this topic. It maybe does the thing that you just might need:http://w3schools.invisionzone.com/index.php?showtopic=28667

Link to comment
Share on other sites

More likely panta wants to change the options in the first select element based on data in the second select element.The select elements will need unique id attributes so you can get references to them.The second will need a function attached to its onchange property. This function will read the value of the select element and update the content of the first. I explain a way for storing the content data below.You get the value of a select element like this:select_value = document.getElementById("my select").value;You can remove all the options from a select elementlike this:document.getElementById("my select").options.length = 0;You'll need to do this before you can add any options. If you don't then you will have all the old options and the new options together.You can add options to a select element using the technique described here.I suggest storing the names and values of the options in global JavaScript arrays. In your case, the names and values can probably be the same, so that makes it simple. Something like this will work:department = new Array();department["Engineering"] = new Array();department["Engineering"][0] = "Mechanical";department["Engineering"][1] = "Chemical";department["Engineering"][2] = "Civil";Just keep following that pattern to store all your data.If you cannot hard-code the data, but need to pull it out of a database using PHP or something, then you would write the JavaScript for those arrays as you loop through your database rows.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...