Javascript: Get Value of DropDown

Posted on 2011-10-03
Last Modified: 2012-06-21
I have 2 drop-down lists on my page.  


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?
Question by:cdemott33
    LVL 81

    Accepted Solution

    <select id="ddlStartTime" onchange="if(document.getElementById('ddlEndTime').selectedIndex<this.selectedIndex) document.getElementById('ddlEndTime').selectedIndex=this.selectedIndex">


    <select id="ddlStartTime" onchange="if(document.getElementById('ddlStartTime').selectedIndex<this.selectedIndex) document.getElementById('ddlStartTime').selectedIndex=this.selectedIndex">

    Author Comment

    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


    Author Comment

    Sorry... typo... I ment to say that your code did not work.
    LVL 81

    Expert Comment

    Dis you notice << id >>

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now