Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Javascript: Get Value of DropDown

I have 2 drop-down lists on my page.  

ddlStartTime
ddlEndTime

Both dropdowns hold the same exact time values, from 8:00 AM to 5:00 PM in half hour increments.

 When a user selects a time in the ddlStartTime DropDownList I want to onChange or onSelect (I'm not sure which) I want the ddlEndTime to change to the time the user select in the ddlStartTime.

So if I choose 10:30 AM, the ddlEndTime value should automatically select 10:30 AM.

How is this done?
0
cdemott33
Asked:
cdemott33
  • 2
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
<select id="ddlStartTime" onchange="if(document.getElementById('ddlEndTime').selectedIndex<this.selectedIndex) document.getElementById('ddlEndTime').selectedIndex=this.selectedIndex">

and

<select id="ddlStartTime" onchange="if(document.getElementById('ddlStartTime').selectedIndex<this.selectedIndex) document.getElementById('ddlStartTime').selectedIndex=this.selectedIndex">
0
 
cdemott33Author Commented:
Hi leakim971 - Unfortunately that did work.  I'm getting an error stating "Object not found".  This is an ASPX page, so I don't know if it needs to be coded differently.  I added the script via the code behind as follows:
ddlStartTime.Attributes.Add("onChange", "if(document.getElementById('ddlEndTime').selectedIndex<this.selectedIndex) document.getElementById('ddlEndTime').selectedIndex=this.selectedIndex")

Open in new window

0
 
cdemott33Author Commented:
Sorry... typo... I ment to say that your code did not work.
0
 
leakim971PluritechnicianCommented:
Dis you notice << id >>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now