Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics 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 April 24th, 2009, 02:13 PM
Authorized User
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default Automatically select value in other combobox

I have two combo box in a page. (number, name) and both of their values are coming from a databse and both of their information is related with each other.

for e.g
number1 name1
number2 name2
number3 name3

When user selects value from number dropdown, it should automatically selects its related name value.
Also when user selects value from name dropdown, it should automatically selects its related number value.

Can anyone please help me how to do this in Classic ASP.

I really appreciate your help.
 
Old April 24th, 2009, 05:25 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You don't WANT to do this in ASP. You want to do it IN THE BROWSER, using JavaScript.

As simple as this:
Code:
<form>
<select name="first" onchange="this.form.second.selectedIndex=this.selectedIndex">
<option>number 1</option>
<option>number 2</option>
<option>number 3</option>
</select>

<select name="second">
<option>name 1</option>
<option>name 2</option>
<option>name 3</option>
</select>
...
</form>

...
This assumes that the options in the two <SELECT>s are related element by element. If it's more complex than that (e.g., maybe the values in the second select are arranged alphabetically?), then the JS code will be longer. But it still won't be complicated.

So if the above doesn't work, show a sample of your *REAL* <SELECT>s.
 
Old April 27th, 2009, 09:19 AM
Authorized User
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply.

Can you please tell me how to display text in another text box when I select some value from one dropdown ?
 
Old April 27th, 2009, 10:13 AM
Authorized User
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can anyone please tell me how to display value part of the dropdown in another text box ?
 
Old April 27th, 2009, 04:40 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Just the value as it is in the <OPTION>??? Any reason to do that, when it is showing as text on the page?

But yes, it's very easy:
Code:
<form>
<select name="selectField" onchange="this.form.textField.value=this.options[this.selectedIndex].text;">
<option value="">--choose one--
<option value="1"> First one
<option value="2"> Playing a secondary role
<option value="3"> Trinity
...
</select>
<input name="textField" readonly> <!--the readonly is optional of course-->
...
</form>





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I select an ITEM from a combobox? Ron Howerton VB.NET 2002/2003 Basics 18 October 2nd, 2015 09:18 PM
Combobox Select/Insert Code osemollie Pro VB Databases 4 June 28th, 2006 09:09 AM
select generated automatically with asp crmpicco Classic ASP Basics 1 July 7th, 2005 04:34 PM
Automatically select value from a calculated field jimmy0305 Access 0 June 21st, 2005 10:43 AM
Automatically select no for dialog box Arsi C# 0 December 10th, 2004 03:46 PM





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