Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 11th, 2003, 08:20 AM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic Query based on drop-down menu

I have a drop-down select menu that contains 10 departments (Department table) in my company. Each department is linkedo one of 5 branches (Branch table). When a user fills out a form and choses a department I want it to autopopulate a text input box with the appropriate branch.
This is the query I want run each time a department is chosen:
Select BranchName from Department where Department= The select box value.

Here is what I have so far. Please help with the JS function:
<SELECT NAME="Directorate" onChange="GetBranch()">
    <OPTION VALUE="Accounting">Accounting
    <OPTION VALUE="MIS">MIS
        <OPTION VALUE="Marketing">Marketing
etc....
</SELECT>
<input type="text" name="branch> <--This field is dynamically populated by the GetBranch() JS function
 
Old June 11th, 2003, 06:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

You could load the data into clientside Javascript arrays or just if / case statements to populate the code, faster to execute, but adds to the download.

Otherwise, you'll have to submit the entire page to the server and get it to reprocess it.

Personally I'd hide an iFrame or Frame in there and use that to communicate with the server and then use Javascript in the response from the server side component to populate the main form, giving you the best of both worlds.
 
Old June 11th, 2003, 11:09 PM
Authorized User
 
Join Date: Jun 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to tgopal
Default

If you are not going to make any database operations based on page and if the page is for just view only then make the code from

<SELECT NAME="Directorate" onChange="GetBranch()">
<OPTION VALUE="Accounting">Accounting
<OPTION VALUE="MIS">MIS
<OPTION VALUE="Marketing">Marketing
</SELECT>

to

<SELECT NAME="Directorate" onChange="GetBranch()">
<OPTION VALUE="Branch1">Accounting
<OPTION VALUE="Branch2">MIS
<OPTION VALUE="Branch3">Marketing
</SELECT>
GetBranch(){
document.forms[0].branch.value=document.forms[0].Directorate[document.forms[0].Directorate.selectedIndex].value
}

or u need to submit the form and u need to reprocess it
 
Old June 16th, 2003, 05:41 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the SELECT it can be that the value does not agree with the visible text:

<select name="Directorate" onChange="getBranch()">
   <option value="accounting">Accounting</option>
   <option value="mys">Mys preferences</option>
   <option value="marketing">The new marketting</option>
</select>
<input type="text" name="branch>

Then the function would change a little:

getBranch(){
document.forms[0].branch.value=document.forms[0].Directorate[document.forms[0].Directorate.selectedIndex].text
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
right click menu hidden by drop-drown menu Andraw HTML Code Clinic 0 March 18th, 2005 03:28 PM
.asp.net dynamic drop down menu fitchic77 .NET Framework 2.0 2 August 12th, 2004 07:39 PM
drop down menu junemo Beginning PHP 2 May 7th, 2004 10:41 AM
Populating Drop Down based on other drop down jeffbarclay Java Databases 1 November 7th, 2003 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.