Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 12th, 2003, 03:41 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Day of week Drop Downs

I am look for code (VBScript or JavaScript) to give 7 drop downs to select a different day of the week from each one. When you select "Monday" from the first drop down, "Monday" is not available in the rest of the drop downs, and so on...

I have a sample one, but only works with 2 drop downs...

Any help would be grateful!

Jeff


Reply With Quote
  #2 (permalink)  
Old November 13th, 2003, 06:34 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

It's fairly straightforward but why not have one list box with two arrows for moving days up or down? It would take up a lot less room.

--

Joe
Reply With Quote
  #3 (permalink)  
Old November 13th, 2003, 01:22 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

And here's two solutions in one page, one uses the method above, the other adds the days to a textarea when you double click on an option.
Code:
<html>
  <head>
    <title>Ordered List</title>
   
    <script type="text/javascript">

      var arrWeekdays = [{"text": "Sunday", "value": 0},
                         {"text": "Monday", "value": 1},
                         {"text": "Tuesday", "value": 2},
                         {"text": "Wednesday", "value": 3},
                         {"text": "Thursday", "value": 4},
                         {"text": "Friday", "value": 5},
                         {"text": "Saturday", "value": 6}
                        ];

      function moveItem(ListboxId, Direction)
      {
        var iSwapIndex = (Direction == "up" ? -1 : 1);
        var oLst = document.getElementById(ListboxId);
        var colOptions = oLst.options;
        var iSelectedIndex = oLst.selectedIndex;
        if (iSelectedIndex == -1) return; 
        var oOption = colOptions[iSelectedIndex];
        if (Direction.toLowerCase() == "up" && oOption.index == 0) return;
        if (Direction.toLowerCase() == "down" && oOption.index == (oLst.options.length - 1)) return;
        var oTempOption = new Option(oOption.text, oOption.value);
        var oSwapWithOption = colOptions[iSelectedIndex + iSwapIndex];
        oOption.text = oSwapWithOption.text;
        oOption.value = oSwapWithOption.value;
        oSwapWithOption.text = oTempOption.text;
        oSwapWithOption.value = oTempOption.value;
        oSwapWithOption.selected = true;
      }
      
      function populateList(ListboxId, Data)
      {
        var oLst = document.getElementById(ListboxId);
        oLst.options.length = 0;
        for (var i = 0; i < Data.length; i++)
        {
          var oOption = new Option(Data[i].text, Data[i].value);
          oLst.options.add(oOption);
        }
        oLst.options[0].selected = true;
        oLst.size = Data.length;
      }
      
      function addToTextArea(Option)
      {
        if (Option.disabled) return;
        Option.disabled = true;
        var oText = document.getElementById("txtSortedList");
        oText.value += Option.text + "\n";
      }
      
      function reset()
      {
        init();
        var oText = document.getElementById("txtSortedList");
        oText.value = "";
      }
      function init()
      {
        populateList("lstWeekdays", arrWeekdays);
      }
      
    </script>
  </head>
  <body onload="init();">
  <table align="left" width="60%" border="0">
  <tbody>
    <tr><td rowspan="2" align="right" width="50%">
    <select id="lstWeekDays" ondblclick="addToTextArea(this.options[this.selectedIndex]);">
    </select></td>
  <td width="*" align="left"><input type="button" value="^" onclick="moveItem('lstWeekdays', 'up');"></td></tr>
  <tr><td align="left"><input type="button" value="v" onclick="moveItem('lstWeekdays', 'down');"></td></tr>
  <tr><td align="right"><textarea readonly style="overflow:hidden" rows="7" cols="12" id="txtSortedList"></textarea></td>
  <td><input type="button" value="Reset" onclick="reset();"></td></tr>
  </tbody>
  </table>
  
  </body>
</html>
--

Joe
Reply With Quote
  #4 (permalink)  
Old November 14th, 2003, 11:14 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe,

Thanks for the code! My page needs to have seven text/dropdown boxes that must all be filled with different days of the week. No two can be the same. This is transferred to a DB for sorting. This is all done in one submit. The method you suggested would not do this.

Thanks for the suggestion though!

Jeff

Reply With Quote
  #5 (permalink)  
Old November 15th, 2003, 05:52 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

With a small addition it would. How does the receiving page need the data, seven differently named items?

--

Joe
Reply With Quote
  #6 (permalink)  
Old November 17th, 2003, 08:28 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, need 7 drop downs, but I need the selections to drop off as they are selected the the last drop down only has one selection...

Jeff

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting the same day of the week. crabjoe Classic ASP Basics 3 February 27th, 2008 12:45 PM
DAY of the week wdepreter Excel VBA 3 February 7th, 2007 06:44 AM
Day of week finder mrjaygreene Classic ASP Basics 6 May 13th, 2006 04:43 PM
Conversion to 7 day week. kinouye BOOK: Beginning VB.NET Databases 0 December 3rd, 2005 03:58 PM



All times are GMT -4. The time now is 09:55 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.