onlick insert date

Discussion in 'Javascript' started by Terje, Nov 17, 2004.

  1. Terje

    Terje Guest

    Have the following code on a checkbox

    onClick="oppdater_levering.leveringsdato.value=eval(<?php echo date('Y-m-d')
    ?>)"

    This should insert todays date into leveringsdato in the form
    oppdater_levering, but in a strange way I get only displayed a strange year
    1976, anyone that can tell me how to make out this?

    Terje
     
    Terje, Nov 17, 2004
    #1
    1. Advertising

  2. Terje

    Erwin Moller Guest

    Terje wrote:

    > Have the following code on a checkbox
    >
    > onClick="oppdater_levering.leveringsdato.value=eval(<?php echo
    > date('Y-m-d') ?>)"
    >
    > This should insert todays date into leveringsdato in the form
    > oppdater_levering, but in a strange way I get only displayed a strange
    > year 1976, anyone that can tell me how to make out this?
    >
    > Terje


    Hi,

    Why do you use eval?
    I don't think Javascript wants to eval something like:

    2004-4-14

    That makes no sense.

    Try this:
    onClick="oppdater_levering.leveringsdato.value=<?php echo date('Y-m-d') ?>)"

    Regards,
    Erwin Moller
     
    Erwin Moller, Nov 17, 2004
    #2
    1. Advertising

  3. Terje

    Terje Guest

    > Try this:
    > onClick="oppdater_levering.leveringsdato.value=<?php echo date('Y-m-d')

    ?>)"
    >
    > Regards,
    > Erwin Moller


    Have tryed both versions, but still I only get "1976" displayed

    Terje
     
    Terje, Nov 17, 2004
    #3
  4. Terje

    Evertjan. Guest

    Terje wrote on 17 nov 2004 in comp.lang.javascript:
    >> Try this:
    >> onClick="oppdater_levering.leveringsdato.value=<?php echo date('Y-m-d')

    > ?>)"
    >
    > Have tryed both versions, but still I only get "1976" displayed


    Single quote the value.
    [Always look at the rendered HTML with view source]


    onClick=
    "oppdater_levering.leveringsdato.value=
    '<?php echo date('Y-m-d')?>'; "



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)
     
    Evertjan., Nov 17, 2004
    #4
  5. Terje

    Terje Guest

    > Single quote the value.
    > [Always look at the rendered HTML with view source]
    >
    >
    > onClick=
    > "oppdater_levering.leveringsdato.value=
    > '<?php echo date('Y-m-d')?>'; "


    Tanks, I've first I made it with a JS dateobject but since this depends on
    that the user have the right timeconfiguration its mutch better to get the
    date from the server with php. This made it work.

    Terje
     
    Terje, Nov 17, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DC Gringo

    2 onlick events?

    DC Gringo, Nov 2, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    492
    gh0st54
    Nov 2, 2004
  2. Lars Netzel
    Replies:
    2
    Views:
    831
    Brock Allen
    Apr 7, 2005
  3. DC Gringo

    2 onlick events?

    DC Gringo, Nov 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    146
    gh0st54
    Nov 2, 2004
  4. Mike Dershowitz

    mixing onlick functions in link_to_function

    Mike Dershowitz, Jun 2, 2007, in forum: Ruby
    Replies:
    2
    Views:
    115
    Rob Biedenharn
    Jun 2, 2007
  5. Cylix
    Replies:
    3
    Views:
    98
    Ian Collins
    Apr 3, 2007
Loading...

Share This Page