473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Dropdownlist change selection on client

Hi group,

I am trying to change the selection of an ASP Dropdownlist just like
"Orange" is selected here:

http://www.w3schools.com/js/tryit.as...ption_selected

The following works fine on IE:

document.getElementById('dropdown').options.select ed = 0 //
selects the first option

But, I need this to work on other browsers as well.

I started by adding the "id" attribute to the ASP:ListItem in order to
access them by their ID (like in the W3C example above), but it does
not get rendered in the produced HTML page.

How could I achieve this in a crossbrowser, standard way?

Thanks.

May 26 '07 #1
11 4442
On May 26, 7:04 am, harold.gime...@gmail.com wrote:
Hi group,

I am trying to change the selection of an ASP Dropdownlist just like
"Orange" is selected here:

http://www.w3schools.com/js/tryit.as...ption_selected

The following works fine on IE:

document.getElementById('dropdown').options.select ed = 0 //
selects the first option

But, I need this to work on other browsers as well.

I started by adding the "id" attribute to the ASP:ListItem in order to
access them by their ID (like in the W3C example above), but it does
not get rendered in the produced HTML page.

How could I achieve this in a crossbrowser, standard way?

Thanks.
Hi,

Please check this link ... in this blog post i have dropped few lines
which might help you
http://munnacs.blogspot.com/2007/05/...ml-select.html

Thanks
Masudur

May 26 '07 #2
On May 26, 12:41 am, Masudur <munn...@gmail.comwrote:
On May 26, 7:04 am, harold.gime...@gmail.com wrote:
Hi group,
I am trying to change the selection of an ASP Dropdownlist just like
"Orange" is selected here:
http://www.w3schools.com/js/tryit.as...ption_selected
The following works fine on IE:
document.getElementById('dropdown').options.select ed = 0 //
selects the first option
But, I need this to work on other browsers as well.
I started by adding the "id" attribute to the ASP:ListItem in order to
access them by their ID (like in the W3C example above), but it does
not get rendered in the produced HTML page.
How could I achieve this in a crossbrowser, standard way?
Thanks.

Hi,

Please check this link ... in this blog post i have dropped few lines
which might help youhttp://munnacs.blogspot.com/2007/05/select-items-of-html-select.html

Thanks
Masudur
Thanks for your reply.

The other thing I tried from your blog did not really work out either:

document.getElementById('dropdown').value = "1";

or

document.getElementById('dropdown').options[1].selected = true;
These two work on IE7 but not Firefox.

I guess the bottom line is: is there a way to assign id s to the list
elements in order for me to access them with getElementById('option1')
on Firefox? Maybe there is a way on the code behind to add this
attribute...

I am using .NET Framework 1.1...

Thanks again.

May 26 '07 #3
On May 26, 6:20 pm, harold.gime...@gmail.com wrote:
document.getElementById('dropdown').options.select ed = 0 //
selects the first option
document.getElementById('dropdown').selectedIndex = 0

should help.

May 26 '07 #4
On May 26, 1:50 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 26, 6:20 pm, harold.gime...@gmail.com wrote:
document.getElementById('dropdown').options.select ed = 0 //
selects the first option

document.getElementById('dropdown').selectedIndex = 0

should help.
Unfortunately it didn't work on Firefox either. Also works fine on IE.
Thanks, though...

May 27 '07 #5
On May 27, 9:39 pm, harold.gime...@gmail.com wrote:
On May 26, 1:50 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 26, 6:20 pm, harold.gime...@gmail.com wrote:
document.getElementById('dropdown').options.select ed = 0 //
selects the first option
document.getElementById('dropdown').selectedIndex = 0
should help.

Unfortunately it didn't work on Firefox either. Also works fine on IE.
Thanks, though...
It does work. I've tested in FF 2.0

Can you give me the full code of your script, please?

May 27 '07 #6
On May 27, 3:54 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 27, 9:39 pm, harold.gime...@gmail.com wrote:
On May 26, 1:50 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 26, 6:20 pm, harold.gime...@gmail.com wrote:
document.getElementById('dropdown').options.select ed = 0 //
selects the first option
document.getElementById('dropdown').selectedIndex = 0
should help.
Unfortunately it didn't work on Firefox either. Also works fine on IE.
Thanks, though...

It does work. I've tested in FF 2.0

Can you give me the full code of your script, please?
Sure. Basically it looks for text in the txtField, and decides what to
select on the dropdownlist depending on empty string or not...

Here is the javascript function which executes on the onchange event
of the txtField...

function setStatus() {
DropDown = document.getElementById('Dropdownlist');
text= document.getElementById('txtField');
if (text.value != "") {
DropDown.selectedIndex = 1;
DropDown.disabled = true;
} else {
DropDown.disabled = false;
}
}

Below is the asp part:

<asp:textbox id="txtField" runat="server" onchange="setStatus()">

<ASP:DROPDOWNLIST id="Dropdownlist" runat="server" >
<ASP:ListItem Value="1">Active</ASP:ListItem>
<ASP:ListItem Value="2">Inactive</ASP:ListItem>
</ASP:DROPDOWNLIST>

Thanks!

May 28 '07 #7
On May 28, 4:27 am, harold.gime...@gmail.com wrote:
On May 27, 3:54 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:


On May 27, 9:39 pm, harold.gime...@gmail.com wrote:
On May 26, 1:50 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 26, 6:20 pm, harold.gime...@gmail.com wrote:
document.getElementById('dropdown').options.select ed = 0 //
selects the first option
document.getElementById('dropdown').selectedIndex = 0
should help.
Unfortunately it didn't work on Firefox either. Also works fine on IE.
Thanks, though...
It does work. I've tested in FF 2.0
Can you give me the full code of your script, please?

Sure. Basically it looks for text in the txtField, and decides what to
select on the dropdownlist depending on empty string or not...

Here is the javascript function which executes on the onchange event
of the txtField...
Hello Harald,

your code is working on my box in IE7, and FF2. It does change an item
in 'Dropdownlist' on onchange event.

Here's my test code (basically, a copy of your code)

<%@ Page Language="VB" %>
<script runat=server>
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Page.IsPostBack Then
response.write("SelectedValue=" &
Dropdownlist.SelectedValue)
End If
End Sub
</script>
<html>
<head runat="server">
<title></title>
<script>
function setStatus() {
DropDown = document.getElementById('Dropdownlist');
text= document.getElementById('txtField');
if (text.value != "") {
DropDown.selectedIndex = 1;
//DropDown.disabled = true;
} else {
DropDown.selectedIndex = 0;
//DropDown.disabled = false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:textbox id="txtField" runat="server"
onchange="setStatus()" />
<ASP:DROPDOWNLIST id="Dropdownlist" runat="server" >
<ASP:ListItem Value="1">Active</ASP:ListItem>
<ASP:ListItem Value="2">Inactive</ASP:ListItem>
</ASP:DROPDOWNLIST>
<asp:Button ID="Button1" runat="server" Text="PostBack" />
</form>
</body>
</html>

In FireFox I see the same behavior, once text is changed and focus is
changed to other control it executes the setStatus() function. When
the button is clicked you will see that the code behind also get the
right value of the control.

Thoughts?

Alexey

May 28 '07 #8
On May 28, 3:30 am, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 28, 4:27 am, harold.gime...@gmail.com wrote:
On May 27, 3:54 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 27, 9:39 pm, harold.gime...@gmail.com wrote:
On May 26, 1:50 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 26, 6:20 pm, harold.gime...@gmail.com wrote:
document.getElementById('dropdown').options.select ed = 0 //
selects the first option
document.getElementById('dropdown').selectedIndex = 0
should help.
Unfortunately it didn't work on Firefox either. Also works fine on IE.
Thanks, though...
It does work. I've tested in FF 2.0
Can you give me the full code of your script, please?
Sure. Basically it looks for text in the txtField, and decides what to
select on the dropdownlist depending on empty string or not...
Here is the javascript function which executes on the onchange event
of the txtField...

Hello Harald,

your code is working on my box in IE7, and FF2. It does change an item
in 'Dropdownlist' on onchange event.

Here's my test code (basically, a copy of your code)

<%@ Page Language="VB" %>
<script runat=server>
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If Page.IsPostBack Then
response.write("SelectedValue=" &
Dropdownlist.SelectedValue)
End If
End Sub
</script>
<html>
<head runat="server">
<title></title>
<script>
function setStatus() {
DropDown = document.getElementById('Dropdownlist');
text= document.getElementById('txtField');
if (text.value != "") {
DropDown.selectedIndex = 1;
//DropDown.disabled = true;
} else {
DropDown.selectedIndex = 0;
//DropDown.disabled = false;
}}

</script>
</head>
<body>
<form id="form1" runat="server">
<asp:textbox id="txtField" runat="server"
onchange="setStatus()" />
<ASP:DROPDOWNLIST id="Dropdownlist" runat="server" >
<ASP:ListItem Value="1">Active</ASP:ListItem>
<ASP:ListItem Value="2">Inactive</ASP:ListItem>
</ASP:DROPDOWNLIST>
<asp:Button ID="Button1" runat="server" Text="PostBack" />
</form>
</body>
</html>

In FireFox I see the same behavior, once text is changed and focus is
changed to other control it executes the setStatus() function. When
the button is clicked you will see that the code behind also get the
right value of the control.

Thoughts?

Alexey
Thanks for that. I helped me identify the issue. The txtField is
actually populated via an RJS Pop Calendar control. Something is
conflicting with the onchange event handler on the txtField and other
code from the pop calendar - BUT, only in FF, which is bizarre to say
the least. The onchange event is not handled by the pop calendar, so
there should be no conflict at all.

I've identified the problem, but still no real solution. I need the
pop calendar since the txtField is supposed to receive a date and I
need to be consistent with the rest of the date input fields...

Alexey, thanks for your help.

-Harold

May 28 '07 #9
On May 28, 7:49 pm, harold.gime...@gmail.com wrote:
Thanks for that. I helped me identify the issue. The txtField is
actually populated via an RJS Pop Calendar control. Something is
conflicting with the onchange event handler on the txtField and other
code from the pop calendar - BUT, only in FF, which is bizarre to say
the least. The onchange event is not handled by the pop calendar, so
there should be no conflict at all.

I've identified the problem, but still no real solution. I need the
pop calendar since the txtField is supposed to receive a date and I
need to be consistent with the rest of the date input fields...

Alexey, thanks for your help.

-Harold- Hide quoted text -

- Show quoted text -
I would suggest to install the Web Developer extension for FF, you
will be able to check js-errors.

May 28 '07 #10
On May 28, 2:37 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 28, 7:49 pm, harold.gime...@gmail.com wrote:
Thanks for that. I helped me identify the issue. The txtField is
actually populated via an RJS Pop Calendar control. Something is
conflicting with the onchange event handler on the txtField and other
code from the pop calendar - BUT, only in FF, which is bizarre to say
the least. The onchange event is not handled by the pop calendar, so
there should be no conflict at all.
I've identified the problem, but still no real solution. I need the
pop calendar since the txtField is supposed to receive a date and I
need to be consistent with the rest of the date input fields...
Alexey, thanks for your help.
-Harold- Hide quoted text -
- Show quoted text -

I would suggest to install the Web Developer extension for FF, you
will be able to check js-errors.
I do have it installed... little green checkmark icon constantly while
looking at this page - no errors, but the event never fires either.

confused :-o)

May 28 '07 #11
On May 28, 2:57 pm, harold.gime...@gmail.com wrote:
On May 28, 2:37 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 28, 7:49 pm, harold.gime...@gmail.com wrote:
Thanks for that. I helped me identify the issue. The txtField is
actually populated via an RJS Pop Calendar control. Something is
conflicting with the onchange event handler on the txtField and other
code from the pop calendar - BUT, only in FF, which is bizarre to say
the least. The onchange event is not handled by the pop calendar, so
there should be no conflict at all.
I've identified the problem, but still no real solution. I need the
pop calendar since the txtField is supposed to receive a date and I
need to be consistent with the rest of the date input fields...
Alexey, thanks for your help.
-Harold- Hide quoted text -
- Show quoted text -
I would suggest to install the Web Developer extension for FF, you
will be able to check js-errors.

I do have it installed... little green checkmark icon constantly while
looking at this page - no errors, but the event never fires either.

confused :-o)
More behaviour observations:

* The event does fire on Firefox when I type in a date to the text
field.
* The event does fire on Firefox when I copy a date and paste it on
the text field.
* The event does NOT fire on Firefox when I select a date on the Pop
Calendar control which populates the text field -this is what user
will do most of the time.

This is what the txtField input looks like rendered on firefox:

<input name="txtField" type="text" id="txtField" autocomplete="off"
Format="mm/dd/yyyy" onfocus="__PopCalSetFocus(this, event);"
onblur="__PopCalSetBlur(this, event);" onchange="setStatus()"
onkeydown="__PopCalValidateKey(this, event);" dir="ltr"
InvalidDateMessage="Invalid Date" Calendar="PopcalendarDate" />

And the pop calender control:

<span id='PopcalendarDate_Control'
onclick='__PopCalShowCalendar("txtField",this)'
style='cursor:pointer;'><img src='/PopCalendar/Calendar.gif'
border='0' align='absmiddle' /></span>

May 28 '07 #12

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

Similar topics

2
by: David Knaack | last post by:
Howdy I'm new to working with DB2 Universal, so I'm not very familiar with the tools. I usually only use the Java Control Center and Configuration Assistant. I have several clients on the...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
2
by: Bob Alston | last post by:
I have an application with several forms. Most forms use radio boxes for Yes/No choices. On a few of these, once one option is selected, the user cannot change the selection without moving to...
4
by: =?Utf-8?B?RGFuaWVs?= | last post by:
Hi, How could I change a WCF client endpoint address programatically? The client is generated by Visual Studio. The purpose of doing this is to use different service address under different...
0
by: myselfgautam.kumar | last post by:
I have three records into Database. Two of them are already displayed into datagrid.Third record which is a parameter , I have to select it from dropdownlist and then insert that record into grid...
0
by: Dhananjay | last post by:
Hi all, i have a webpage on which first thing i am adding record using textboxadd and buttonadd. ------ this works fine second thing i have dropdownlist box on which i will select an item,...
2
by: Ben | last post by:
Hi, i'm trying to get an AJAX modalpopup to confirm if a user really wants to change a dropdown list value (on the client side) -- if they choose 'No' in the popup, the dropdown list value...
5
by: =?Utf-8?B?U2F0aXNo?= | last post by:
C#, ASP.NET Q: Have a formview, with a dropdownlist which is bound to a column. This dropdownlist has a datasource of DataSet type. Now my objective is, on Selection Changed of this DropdownList,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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,...

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.