Jump to content
Sign in to follow this  
Panta

How Does A Drop Down Works

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>

Share this post


Link to post
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

Share this post


Link to post
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.

Edited by Deirdre's Dad

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...