473,796 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Auto select drop down list after post back?

Hi all,

I post back to my page if the form hasn't been submitted with the required
information. I would like to with a little javascript, auto-select an
option in the drop down list on my page.

The drop down list is called lstCountry

I will have in an ASP variable the country code which was the value of the
selected item when the form was posted...

I would like to do something like...

lstCountry.opti ons[<%=strCountry %>].selected = true

I think however the value between the square brackets has to be a number
relating to the index of the option?

Can anyone help me with this please...

Regards

Rob
Jul 26 '06 #1
1 7955
Rob Meade said the following on 7/26/2006 6:11 PM:
Hi all,

I post back to my page if the form hasn't been submitted with the required
information. I would like to with a little javascript, auto-select an
option in the drop down list on my page.
Find the option, and add the selected attribute to it using ASP:

<option value="someValu e" selected>Option Text</option>

No need to use client side scripting at all.
The drop down list is called lstCountry

I will have in an ASP variable the country code which was the value of the
selected item when the form was posted...

I would like to do something like...

lstCountry.opti ons[<%=strCountry %>].selected = true

I think however the value between the square brackets has to be a number
relating to the index of the option?
Yes.
Can anyone help me with this please...
See Above.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 27 '06 #2

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

Similar topics

9
11855
by: Prowler | last post by:
In our current application we have a page whose sole purpose for existence is to permit the user to select from a list (subsequent to our login page). We would like to have the list drop down automatically when the visitor arrives at the page, perhaps by using the onLoad event to call the dropdown code. The problem is, the click() event does not drop down the list, as I would have thought it might. I can successfully fire other methods...
1
2167
by: craig | last post by:
Hi, I've been asked to create a page that dynamically populates the contents of related drop down lists using JavaScript, and then obviously posts things back to the server. For completeness, I re-produce example JavaScript below (this seemingly works fine - but just to let you see what is going on) e.g. var categoriesArray = TrendCategoriesHolder;
1
2503
by: pmelanso | last post by:
Hello, I have a drop down list which is dynatically loaded from a database and I have a second drop down list that is also dynatically loaded depending on what is selected in the first drop down box. This all works fine ... what isn't working is when I selected a different item in the first drop down list I want it to automatically reload the items in the second drop down list. I have a funcation called loadNames that laod the second...
5
17686
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600. The species list has 7 fields the first is a four digit unique identifier (species) it is set as the primary key. I have created a relationship to the data collection table which also has a species field (4 digit id). In my form I have the species...
11
3200
by: C10B | last post by:
hi all, I have 3 drop down lists. When any of them changes there is an auto postback to do some server stuff. It is not always obvious (as a user) that a page reload has been started, and you can start selecting other options and then suddenly the page refreshes. It would be great to show "please wait" when the postback is
1
1487
by: gauravtechie | last post by:
Hi all, I have a javascript that is reloading itself on every menu change, Now the problem is that the values of the product doesn`t reset itself on catalogue change, the code is <html> <head> <title></title>
4
14197
by: magmike | last post by:
I've got a control on my form that allows the user to select a record based on a form field (in this example, the drop down menu shows the company name, followed by the contact name but uses the contactid to change the data on the form). Most users, start typing the company name which will auto complete itself with the first entry with the letters typed so far. They can then click on the arrow to view the listings, select the one they want...
2
3340
by: crazychrisy54 | last post by:
Hi there I have a option, select drop down list which a user can open. My page however refreshes very frequently and when this occurs the selected drop down list will pop back up. The user then has to open the drop down list again. I just wondered if there was a way using javascript to firstly detect if the user has selected the drop down list and if so, on refresh to set that drop down list to stay dropped down?
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10174
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,...
0
10012
tracyyun
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...
0
9052
agi2029
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...
1
7548
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
6788
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();...
1
4118
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
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
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.