473,398 Members | 2,404 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.

Checkbox/selectedIndex of Dropdown

markrawlingson
346 Expert 100+
Hi guys,

I have a bunch of drop down lists on a page, with a checkbox beside each one that relates to each one respectively. When a user selects an option from the drop down, the checkbox is automatically checked, if the user unchecks the checkbox, the dropdown list is automatically reset to "select" which is the default option.

What I'm trying to do is have the dropdown list set to the first item if the user checks the checkbox. My attempts at this are failing, is there a problem with the code below?

Expand|Select|Wrap|Line Numbers
  1.     function CheckDropDown(sFieldID,sNumID) {
  2.         if (!document.getElementById(sFieldID).checked) {
  3.             document.getElementById(sNumID).selectedIndex = document.getElementById(sNumID).options[0];
  4.         }
  5.         else {
  6.             document.getElementById(sNumID).selectedIndex = document.getElementById(sNumID).options[1];
  7.         }
  8.     }
  9.  
This function is called OnClick of course. So it should check to see whether the checkbox is checked... and if it isn't, reset the respective dropdown list to index 0 ("select") and if it is checked, set it to the lowest option in the dropdown list which will be at index 1.

However, no matter whether the box is checked or not, it always sets it to index 0, which is fine when the user unchecks the checkbox, but not when the user checks the checkbox. Not sure why it's doing this, it looks like it should work.

Thanks guys.

Sincerely,
Mark
Oct 26 '07 #1
2 6966
markrawlingson
346 Expert 100+
Nevermind, I fixed this problem by referring the the selectedIndex as 1.

Now this script works perfectly in IE but does not work what so ever in firefox.

Can anyone point out why?

Sincerely,
Mark
Oct 26 '07 #2
acoder
16,027 Expert Mod 8TB
Now this script works perfectly in IE but does not work what so ever in firefox.

Can anyone point out why?
Show the code for the dropdown.
Oct 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Angel | last post by:
I have a problem I placed a DropDown list control on my .NET page. I do not want to perform a postback when something is selected. When I want to get what was selected in the Client Script I do not...
2
by: 23s | last post by:
I have a dropdown bound to a dataview. The binding assigns the dropdown with a SelectedIndex of 0. There is a msgbox in the SelectedIndexChanged event that displays the SelectedIndex property....
4
by: Kalvin | last post by:
I have seen this question raised, but I cannot find an answer. I have an MDI app, when I load an child form with a combobox being bound in the load event, it won't allow me to set selectedindex =...
3
by: devNorway | last post by:
I have been struggling with a problem for days now, and searched for related problems and solutions but had no luck. I have two dropdown listboxes where the first is populated in page load and...
4
by: in da club | last post by:
I have a datagrid and a dropdown in my page. I want to fill dropdown with my pagenumbers. When a user change the dropdown selected index i wnt to display the result on label1. Anytime i change the...
0
by: cvijaykrishna | last post by:
i am having a web based application and i am having a problem with it pls check it Explanationi am sending a sample code plese see it in VS-2005 FOR BETTER UNFERSTANDING I have a main page...
5
by: Rotsey | last post by:
Hi, I have a combobox that when I set the SelectedIndex to -1 it sets to 0. The combobox Items property says there is 20 items in it. Anyone know why this could be please? rotsey
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
5
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post by:
I have a VS 2008 ASP.NET webform that has a reportview tag on it, accessing an .RLDC report in local report. The columns for the report are essentially: Month Item #1 Item#2 Item#3 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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
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...
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,...
0
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...

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.