Web Analytics Made Easy -
StatCounter date in textbox - CodingForum

Announcement

Collapse
No announcement yet.

date in textbox

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • date in textbox

    i want to insret the current date in textbox but this code dosen't work and the value of text box will be "date()"



    function date()
    {
    var mydate=new Date()
    var year=mydate.getYear()
    if (year < 1000)
    year+=1900
    var day=mydate.getDay()
    var month=mydate.getMonth()+1
    if (month<10)
    month="0"+month
    var daym=mydate.getDate()
    if (daym<10)
    daym="0"+daym
    today=day+month+year;
    return today;
    }


    <INPUT id=text3 name=text3 value="date()" >

  • #2
    date is a reserved word in javascript, so you can't name a function date(). also, you can't put a javascript function into html like that. you'd have to set the value of the form using the window's onload event.

    function today() {
    var mydate = new Date();
    var year = mydate.getFullYear();
    var day = mydate.getDay();
    var month = mydate.getMonth() + 1;
    if (month < 10) {
    month = "0" + month;
    }
    var daym = mydate.getDate();
    if (daym < 10) {
    daym = "0" + daym;
    }
    return ('' + day + month + year);
    }

    window.onload = function() {
    document.theForm.text3.value = today();
    }


    <INPUT id=text3 name=text3>
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      thank you

      Comment


      • #4
        Hi joh6nn,

        date is not a reserved word in javascript.

        ( •) (• )
        >>V
        owl3d.com

        Comment


        • #5
          Originally posted by joh6nn
          date is a reserved word in javascript, so you can't name a function date().
          Well, actually, since JavaScript is case-sensitive... date() would not be reserved and could be used as a user function name. Date(), however, would be the reserved form.

          OK?

          Comment


          • #6
            Hi Dave,

            Date is not a reserved word in javascript.
            You may use it as a user function name.

            ( •) (• )
            >>V
            owl3d.com

            Comment


            • #7
              Originally posted by Owl
              Date is not a reserved word in javascript.
              You may use it as a user function name.
              Don't be an imbecile. You're just taking up space on the server for your idiotic plays on the actual definition and normal usage of the word "reserved". So, as long as you're going to make esoteric denials of the viability of the comments of others -- without further explaining your lunacy -- then it would be far better off, for all, for you to just shove off and go play your games elsewhere.

              So, to explain (for the simple-minded who don't know how to loosely apply a word to a situation)... "Reserved" is used in the general sense of "if you don't want to lose any of the standard JavaScript functionality." In other words... If you create your own function, called Date(), then you will no longer be able to get the normal "Date" functionality, of the JavaScript Date() constructor, by any other normal means.

              OK?

              Comment


              • #8
                Dave, just so you know, i've had both Explorer and Mozilla throw errors at me, more than once, when trying to use 'date' as a variable name. only variable name i've ever had the problem with, so it's also possible that i'm misremembering, or mistaken. was with a pre 1 release of Mozilla, and i think it was with IE5, so it may no longer be an issue, if it ever was, but in my experience, 'date' acts like a reserved word, even if in theory, it isn't.

                be interesting to know if anyone else has ever encountered the same, or something similar.
                bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

                i am a loser geek, crazy with an evil streak,
                yes i do believe there is a violent thing inside of me.

                Comment


                • #9
                  Originally posted by Dave Clark


                  Don't be an imbecile. You're just taking up space on the server for your idiotic plays on the actual definition and normal usage of the word "reserved". So, as long as you're going to make esoteric denials of the viability of the comments of others -- without further explaining your lunacy -- then it would be far better off, for all, for you to just shove off and go play your games elsewhere.
                  Dave, in all Javascript references, there is a clear distinction about exactly what a reserved word is. You've linked to the references in your signature, certainly you can respect the real definition.

                  It is very incorrect to say that just because you shouldn't use it, means that it is reserved.

                  And if I was Owl, I would have taken offense at your post. Try to be nicer - though nice usage of vocabulary .

                  To quote you, "OK? "
                  jasonkarldavis.com

                  Comment


                  • #10
                    Originally posted by jkd
                    Try to be nicer ...
                    I *can* be nicer -- when others are trying to be reasonable. Some of your recriminations should have gone the other way -- a little less one sided, in this situation.

                    It would have been different if the person in question had done more than just tell others that they were wrong. To tell someone that they are wrong and "walk away" is rude, crude, and immature (sorry couldn't rhyme that one ). Such an "accusation" demands an accompanying explanation.

                    OK?

                    Comment


                    • #11
                      Everyone on this thread fails the test for language lawyer certification. One must learn to play nice in courts during the heat of debate.

                      Comment


                      • #12
                        Hi Jason,

                        Sure glad to see one of the mods finally picking this one up.
                        I was beginning to think this is the regular language around here.

                        We both know that in the place where I come from, this
                        would be Daves one before last post using such language.

                        Any way, congrats on your new title kid.
                        Remember: with greater title comes greater responsibility !

                        ( •) (• )
                        >>V
                        owl3d.com

                        Comment


                        • #13
                          Remember: with greater title comes greater responsibility !
                          Hmmm...from what comic could that have been parodied?

                          Happy coding!

                          Comment


                          • #14
                            Originally posted by Dave Clark
                            It would have been different if the person in question had done more than just tell others that they were wrong. To tell someone that they are wrong and "walk away" is rude, crude, and immature (sorry couldn't rhyme that one ). Such an "accusation" demands an accompanying explanation.

                            OK?
                            On a personal note, I would consider this part claiming your post incorrect:
                            Date is not a reserved word in javascript.
                            And this part explaining why:
                            You may use it as a user function name.
                            Albeit short, but sweet.

                            On an official note, could we consider this matter dropped, for the sake of maintaining the friendly atmosphere that is typical of CodingForum?


                            And on a side note, Owl and nolackymose, do I sense a JavascriptCity/PageResource migration?
                            No offense to your native forums, but I find that CodingForum generally offers faster and more helpful replies in a greater quantity.

                            Enjoy the forums, and don't let one incident ruin your impression.
                            jasonkarldavis.com

                            Comment

                            Working...
                            X