Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    tho
    tho is offline
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy dropdown selection to another dropdown?

    Hello, I am completely new to HTML/JS/CSS, therefore I know very little.

    I have two drop-down prompt controls with month names. One has just one value (say "July") and the other has all the months of the year ("January".."December"). The first prompt control is hidden on the page. How do I set the default selection of the second prompt control to the value present in the first prompt control? So, when the page is run, the second prompt control should automatically show "July".

    I was reading up on the selectedIndex property (?), but I know that it won't work because I want Index 0 to be selected in the first control and Index 6 in the second, and I expect it to change every month (next month it will be index 7 that should be automatically selected).

    If it matters, I am using IE8. Thanks!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,029
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    If I understand you correctly, you simply want the current month to be selected in the drop-down.

    Code:
    <body onload ="showMonth()">
    
    <form>
    <select name = "months">
    <option value = 1>January</option>
    <option value = 2>February</option>
    <option value = 3>March</option>
    <option value = 4>April</option>
    <option value = 5>May</option>
    <option value = 6>June</option>
    <option value = 7>July</option>
    <option value = 8>August</option>
    <option value = 9>September</option>
    <option value = 10>October</option>
    <option value = 11>November</option>
    <option value = 10>December</option>
    </select>
    </form>
    
    <script type = "text/javascript">
    function showMonth() {
    var d = new Date().getMonth();
    document.forms[0].months.selectedIndex = d
    }
    
    </script>
    If that is not what you want, please explain more clearly. What is the point of a select list with only one option? Especially if it is hidden! You can of course easily manipulate the selected month to be two months ahead or whatever.


    When trouble arises and things look bad, there is always one individual who perceives a solution and is willing to take command. Very often, that individual is crazy.
    Last edited by Philip M; 09-06-2011 at 05:45 PM. Reason: Typo

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    tho
    tho is offline
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks for the reply. You're right that I want the current month, but I wanted help with a reporting application and "current month" for our database is July. I no longer have this requirement; thanks again though.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •