473,887 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I dynamically populate data when selecting an option from a dropdown list?

I have a JSP page and it contains a dropdown list called Office.

What I try to do is:

When I select different office from this list, the information of office
(address, phone,etc) will be populated in same JSP page.

I have a java bean called officeBean that contains all the office

My question is how to use JavaScript to implement this function.

Any sample code is welcome.

Jul 23 '05 #1
1 3619
jzhang29 wrote:
I have a JSP page and it contains a dropdown list called Office.

What I try to do is:

When I select different office from this list, the information of office (address, phone,etc) will be populated in same JSP page.

I have a java bean called officeBean that contains all the office

My question is how to use JavaScript to implement this function.

Any sample code is welcome.


<title>untitled </title>
<style type="text/css">

input, select {
font: 12px tahoma;
text-align: right;
padding: 2px;
border: 1px #000 solid;

<script type="text/javascript">

var offices =

'Shanghai' :
address: '223 Willow Way' ,
phone: '22-435-4857' ,
carpet: 'brown shag'

'Tokyo' :
address: '223-55 Ginza' ,
phone: '333-435-4857' ,
carpet: 'Karastan Blue'

'San Francisco' :
address: '511 Embarcadero' ,
phone: '415-786-4908' ,
carpet: 'red linoleum'

'London' :
address: '5 Charing Cross' ,
phone: '4-77-888-3847' ,
carpet: 'brown shag'

'Tikrit' :
address: '19 Rubble Street' ,
phone: 'n/a' ,
carpet: 'flying'

'default' :
address: '' ,
phone: '' ,
carpet: ''


function populate(obj)
var v = obj.options[obj.selectedInd ex].value,
office = offices[v || 'default'],
bullet = '· ';
if (null != office)
for (data in office)
if (field = document.getEle mentById(data))
field.value = bullet + office[data];

<select name="office" onchange="retur n populate(this)" >
<option value="">- pick -</option>
<option value=""></option>
<option value="Shanghai ">Shanghai</option>
<option value="Tokyo">T okyo</option>
<option value="San Francisco">San Francisco</option>
<option value="London"> London</option>
<option value="Tikrit"> Tikrit</option>
</select>___selec t an office...
<hr />
value="· " />__address<br />
value="· " />__phone<br />
value="· " />__carpet<br />

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Lukelrc | last post by:
Hi, I have a dynamically created listbox. I'm trying to get one of the options selected according to a passed value. This is what i have: <select name="txtTheme" id="txtTheme"> <option>Select Theme</option> <% Dim PassedTheme
by: Rod Early | last post by:
I need to know when the select element's dropdown list is opened (as when the user clicks on the arrow or does ALT-downarrow from the keyboard). Similarly, I need to known when the dropdown list closes. The closing of the dropdown list can happen without changing the dropdown, hence the onchange event is not a sure way to determine that the dropdown list closed. Is this possible in Internet Explorer?
by: cjm | last post by:
I have two problems that I suspect will be bread-and-butter problems for the more experienced guys on here, but I'm not the greatest with js. NB: Code snippets at the bottom The first problem is that after a bit of fiddling I'm getting am 'Object Expected' error when I click on the Depot dropdown which I can't seem to get round. The code I had was working OK but then I cut it all out, tidied it all up, and put it back in and now it...
by: Dmitry Korolyov [MVP] | last post by:
Is that possible? In other words, I want a dropdown list (and other list-type controls) which appears in edit more of a templated column to be populated with data at the run time. An attempt to do so results in non-existing object error. (Object reference not set to an instance of an object). -- Dmitry Korolyov MVP: Windows Server - Active Directory
by: murphy | last post by:
Hello, I've run into a potentially wrong design decision on a project and want to find out if my intended change is the best fix. I have a page that displays historical time-series data using a datagrid. The browser can modify the timeframe displayed by selecting a value from a dropdown list of 1 day, 1 week, 1 month or previous months.
by: Advertis | last post by:
Is there a way to populate a dropdown in a GridView with the next x years? I am using a GridView to display data from a SQL table One of the fields is a Year. I want to have the dropdown list not only the year in the db field, but also the current year to the next x years. Any ideas?
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply.
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp textbox control which has a 'TextMode' property and when clicked on, displays as a dropdown list with 3 values, I want to have a similar type property with a dropdown style.
by: itgaurav198 | last post by:
Hi, I have an arraylist(al) in which I have some values. I want to populate these values in my dropdown list. I have used the following code <select name="select"> <%for(int i=0;i<al.size();i++){%> <Option value="<%al.get(i);%>"><%=al.get(i)%></Option> <%}%> </select>
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.