473,756 Members | 3,211 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
information.

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

Any sample code is welcome.

Kevin
Jul 23 '05 #1
1 3610
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
information.

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

Any sample code is welcome.

Kevin


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled </title>
<style type="text/css">

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

</style>
<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];
}
}

</script>
</head>
<body>
<form>
<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 />
<input
type="text"
id="address"
name="address"
value="· " />__address<br />
<input
type="text"
id="phone"
name="phone"
value="· " />__phone<br />
<input
type="text"
id="carpet"
name="carpet"
value="· " />__carpet<br />
</form>
</body>
</html>

Jul 23 '05 #2

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

Similar topics

5
2068
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
1
10152
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?
4
2278
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...
3
3804
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
1
1200
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.
3
2112
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?
4
2715
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.
0
1613
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.
1
1601
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>
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
Oralloy
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...
0
9872
jinu1996
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...
1
9843
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,...
1
7248
isladogs
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...
0
6534
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();...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.