Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts

    today's date in form field

    http://javascriptkit.com/script/scri...ateform2.shtml

    For the date script at above url, what if I want two or more date fields in the same form[same page] showing ALL CURRENT DATE , what to do ?

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    just like that:
    what if I want two or more date fields in the same form[same page] showing ALL CURRENT DATE , what to do ?
    What if?

    What is your aim, after all?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    <body onload="SetToToday('FirstSelect'); SetToToday('SecondSelect');">

    name the new drop down as 'SecondSelectDay', 'SecondSelectMonth', 'SecondSelectYear'...

    and change the onchange call for each drop down...
    <SELECT name="SecondSelectMonth" onchange="ChangeOptionDays('SecondSelect')">

    do the same for third, fourth, fifth date fields...
    - NS 666
    .net DEVILoper

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Similarly to Nischumacher's solution, except that a number is used inside the name instead of 'first', 'second', etc. This allows a loop to be used...
    Code:
    <script type="text/javascript">
      function setDateFields()
      {
        for(var index=0; index<5; index++) // Assuming you have 5 sets of date lists
        {
          SetToToday('Select'+index);
        }
      }
      function setToToday(dateField)
      {
        // Enter your code from site here...
      }
      window.onload=setDateFields;
    </script>
    There's just a few changes that you would need to be aware of doing it this way....
    • Variable names cannot begin with numbers; hense I started the names with 'Select' and added the numbers to the second position. Thus the drop-down lists get named: 'Select1Day', 'Select1Month', and 'Select1Year' respectively.
    • Because of the new naming styles, the onchange would get changed to:
      onchange="ChangeOptionDays('Select1')"
    • I've also put the page's onload inside the <script> tags (which you could place inside the <head> of your page). Thus you won't call onload="..." inside the <body>.
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!

  • #5
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://www.frontpagewebmaster.com/fb.asp?m=306965

    Please review the forum answer to above url and answer:

    I do this but,
    in frontpage "Preview Mode" appears good(date current for both) but when publish it to www the date is not current for both date fields but 01 jan 2006 ?
    ----------------------
    also another problem: after pressing "submit" form a "FrontPage Error." appears, well, please test it and view source code at :

    http://polis-index.com.cy/test-sd/two-date-fields.htm

  • #6
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can't you populate the other from the values of the first one?

  • #7
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what you mean , please say it more describetive ?

  • #8
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts
    please say it in more detail

  • #9
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    Code:
    <html>
    <head>
    <script type="text/javascript">
    	
    	window.onload=function(){
    		var defaultDate = new Date();
    		var todayStr = 
    
    defaultDate.getMonth()+1+"/"+defaultDate.getDate()+"/"+defaultDate.getFullYear();
    		document.forms[0].isToday1.value = todayStr;
    		document.forms[0].isToday2.value = todayStr;	
    		document.forms[0].isToday3.value = todayStr;
    	}
    
    </script>
    </head>
    <body>
    <form name='anyName'>
    Today is: <input type=text size=9 name='isToday1' readonly><br>
    Today is: <input type=text size=9 name='isToday2' readonly><br>
    Today is: <input type=text size=9 name='isToday3' readonly><br>
    </form>
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •