SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript changing the options of the second select box depending on the first

    I have two text boxes one with months in "January, Febuary..." but as not every month has the same ammount of days i need the second select box to change to instead of having options 1-30 it has 1-28 or what ever depending on what month is selected.

    Any one know how to do this?

    Hope that made sense

  2. #2
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
      <meta content="text/html; charset=UTF-8" http-equiv="content-type">
    
    <script type="text/javascript">
    
    function change () {
    var el = document.getElementById('sel0');
    var sel = document.getElementById('sel1')
    var d = new Date();
    var d2 = new Date(d.getFullYear(),el.selectedIndex + 1, 0);
    sel.options.length = 0;
    for(var i = 1; i <= d2.getDate(); i++ ) {
    sel.options[sel.options.length] = new Option(i,i);
    }
    }
    </script>
    </head>
    <body>
    
    <select id="sel0" onchange="change()">
    <option>January</option>
    <option>February</option>
    <option>March</option>
    <option>April</option>
    <option>May</option>
    <option>June</option>
    <option>July</option>
    <option>August</option>
    <option>Eyl&#252;l</option>
    <option>Ekim</option>
    <option>Kasım</option>
    <option>Aralık</option>
    </select>
    
    <select id="sel1"></select>
    Last edited by muazzez; Oct 18, 2007 at 03:37.
    Bismillahirrahmanirrahîm
    Bizi doğru yola, kendilerine nimet verdiklerinin yoluna ilet; gazaba uğrayanların ve sapıklarınkine değil.


Bookmarks

Posting Permissions

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