SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please Mods don't kill me, I have already posted this question in the Beginners Forum but I was told over there to ask the question over here. So I'm posting it here again.
    "I want to make a form for my users where they can submit deals. On the form there is a drop down menu for Exp. dates, for the dd/mm/yy. My question is how can I make that the default exp. date should change every day according to that date. If you want to see what I'm talking about you can give a look on the form at my site at http://jumpondeals.com/submitdeals.htm (right now the form is set to 11/21/00 but it doesn't change automatically).
    Don't wander around in my site cause it's still under construction."




    Edited by fello9 on 11-21-2000 at 09:37 PM

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi fello9,

    Tried following the link -- no go. So, I'm not exactly sure how you are currently implementing your problem. However,......

    The following code will change the selection list's option's value &/|| text:

    document.formname.selectname.options[optionNumber2Change].text = someText;

    document.formname.selectname.options[optionNumber2Change].value = someValue;

    You should put the above in a function and call it with the onLoad event handler in the body tag. (If you leave it outside a function, there is a good chance, you'll end up with an object undefined or has no properties message.)

    If you want to insert the current date, you can use some of the code in the following thread (posted by one of the other moderators: westmich)

    http://www.sitepointforums.com/showt...threadid=11906

    Notes:
    1) dependent upon how your selection list looks and is implemented, you may have to execute a reload() for netscape to redraw the screen.
    2) You can also place the function directly after the selection list tag, or document.write the option in its appropriate place on the page.

    Vinny

    Edited by Vincent Puglia on 11-21-2000 at 09:38 PM
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, sorry for the link failure it was my problem as I have changed that file name, but I have corrected it now. On that page you'll see a drop down menu for the exp. date. What I want is that the default date which is filled in automatically in the drop down menu should change every day according to that days date.
    Thank you so much Vincent Puglia, but can you please explain to me better what to do?



    Edited by fello9 on 11-21-2000 at 09:47 PM

  4. #4
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <HTML>

    <BODY>

    <FORM NAME="TheDate">

    <SELECT NAME="TheDay">
    <OPTION value=01>01
    <OPTION value=02>02
    <OPTION value=03>03
    <OPTION value=04>04
    <OPTION value=05>05
    <OPTION value=06>06
    <OPTION value=07>07
    <OPTION value=08>08
    <OPTION value=09>09
    <OPTION value=10>10
    <OPTION value=11>11
    <OPTION value=12>12
    <OPTION value=13>13
    <OPTION value=14>14
    <OPTION value=15>15
    <OPTION value=16>16
    <OPTION value=17>17
    <OPTION value=18>18
    <OPTION value=19>19
    <OPTION value=20>20
    <OPTION value=21>21
    <OPTION value=22>22
    <OPTION value=23>23
    <OPTION value=24>24
    <OPTION value=25>25
    <OPTION value=26>26
    <OPTION value=27>27
    <OPTION value=28>28
    <OPTION value=29>29
    <OPTION value=30>30
    <OPTION value=31>31
    </SELECT>

    <SELECT NAME="TheMonth">
    <OPTION value=01>JAN
    <OPTION value=02>FEB
    <OPTION value=03>MAR
    <OPTION value=04>APR
    <OPTION value=05>MAY
    <OPTION value=06>JUN
    <OPTION value=07>JUL
    <OPTION value=08>AUG
    <OPTION value=09>SEP
    <OPTION value=10>OCT
    <OPTION value=11>NOV
    <OPTION value=12>DEC
    </SELECT>

    <SELECT NAME="TheYear">
    <OPTION value=2000>2000
    <OPTION value=2001>2001
    <OPTION value=2002>2002
    <OPTION value=2003>2003
    <OPTION value=2004>2004
    <OPTION value=2005>2005
    </SELECT>

    </FORM>

    <SCRIPT>
    NowDate = new Date();
    document.TheDate.TheDay.options.selectedIndex = NowDate.getDate()-1;
    document.TheDate.TheMonth.options.selectedIndex = NowDate.getMonth();
    Y = NowDate.getYear();
    if (Y < 1000) Y +=1900;
    document.TheDate.TheYear.options.selectedIndex = Y-2000;
    </SCRIPT>

    </BODY>

    </HTML>

  5. #5
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    etlux thnx! But I need some more help.

    Thank you so much etlux. Do I have to enter somewhere today's date, or it takes the date from the server?
    Also if I want to set the form in a way that the date should appear one day later than the current date i.e. on November 23, the form should show November 24, what should I do? (The reason why I want it this way is because an exp. date will usually not be entered for the same day).



    Edited by fello9 on 11-23-2000 at 10:32 AM

  6. #6
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This script takes the date from the user's system (via the browser, of course)... so it would reflect the current date as set there.

    So far as I know, there's no convenient way to get the date off the server via JavaScript -- for that, you would need to go server-side.

    To get the date of the following day would rather complicate the script, as you need to allow for rollovers at the end of the month, and at the end of the year.

  7. #7
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Etlux so you can't tell me how to make that the default exp. date should be one date ahead? Please tell me. I'll appreciate it very much.
    Thank you in advance!

    Edited by fello9 on 11-23-2000 at 01:21 PM

  8. #8
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I'm trying to think up a straighforward way to do that, which doesn't involve all sorts of arrays and exceptions to manage months of different lengths, leap years, etc.

    Anybody got any boilerplate on this?

  9. #9
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Greetings & Happy Gobblegook to ye all.

    use getTime() add 24hours and then setTime()

    Fello9: If you are a newbie, I recommend the following:

    1) http://htmlgoodies.earthweb.com -- the javascript primer. It is geared for newbies, well-written, and amusing.

    2) a book for beginners, something on the order of SAM's Javascript in 24 Hours.

    If you have some javascript or programming knowledge:

    1) O'Reilly's Javascript: The Definitive Guide
    2) Danny Goodman's Javascript Bible

    Don't eat too much bird

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  10. #10
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got some flaky results with that in NS, Vinny -- that's why I didn't suggest it. You wanna check it, see what you get?

  11. #11
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi etLux,

    I'm not on my primary machine, so I can't upload the code; but, if I remember right, it does work -- though the last method call may be setDate() (?) in the (yyyy,mm,dd) format. If I'm still awake when I get home, I'll check.

    What sort of results were you getting?

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  12. #12
    SitePoint Addict
    Join Date
    Oct 2000
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    NS and IE process dates differently, so I may just have run afoul of that. While IE processes year dates correctly, NS adheres to the absurd standard used by Perl.

    For instance,

    <script>
    NowDate = new Date();
    Y = NowDate.getYear();
    document.write(Y);
    </script>

    will correctly return 2000 for the year in IE -- while Netscape will return... 100.




  13. #13
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi etLux,

    Never did make to the primary, but try this:

    var today = new Date();
    var todayInMsecs = today.getTime();
    var dayInMsecs = 60 * 60 * 24 * 1000;
    var tomorrowInMsecs = todayInMsecs + dayInMsecs;
    var tomorrow = new Date(tomorrowInMsecs);

    If I remember right getYear() only produces the last two digits, so Netscape would come up with the Y2K thingy. getFullYear() might work, but I've never played with it.

    fello9: You listening? If you want to target a date beyond today you simply need to multiply dayInMsecs by the number of days from the present

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •