Results 1 to 3 of 3

Thread: Change weekday by date

  1. #1
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Change weekday by date

    Hi guys,

    As I'm hopeless with Javascript, I've been searching for a way to change the weekday in a text box by date selection in a drop down.

    I am trying to design a timecard application where users can insert upto 10 records in the database at a time. Each row starts with date which (drop down shows the last 28 dates) - when the user selects any date from this list, I need the value in the input box next to it to change to the weekday corresponding with the date.

    However, I need to keep the value of the date in the drop down too, ie, I need the date and the day as parameters for the next page, so, the following won't work:

    <html>
    <head></head>
    <body>

    <form id="myform" name="myform" method="post" action="gotonextpage.asp">

    <select id="mydates" name="mydates"
    onchange="document.getElementById('myday').value=this[this.selectedIndex].value">
    <option value="Monday">17/07/2006</option>
    <option value="Sunday">16/07/2006</option>
    <option value="Saturday">15/07/2006</option>
    </select><br />


    <input id="myday" name="myday" type="text" value="" /><br />

    <input type="submit" value="Submit" />
    <input type="reset" value="Clear" />
    </form>

    </body>
    </html>


    Any help will be greatly appreciated.

    Regards,

    Manny

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <script type="text/javascript">
    var monthDB = {
      '17/07/2006' : 'Monday',
      '16/07/2006' : 'Sunday',
      '15/07/2006' : 'Saturday'
    };
    </script>
    <select onchange="this.form.elements['myday'].value = monthDB[this.value];">
      <option value="17/07/2006">17/07/2006</option>
      <option value="16/07/2006">16/07/2006</option>
      <option value="15/07/2006">15/07/2006</option>
    </select>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Twey,

    You are a superstar!! I've been trying to get this working for five days now and always managed to do one bit but not the other. You've just saved me a lot of time.

    Thanks again,

    Manny

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
  •