SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: date issue

  1. #1
    SitePoint Member
    Join Date
    Feb 2003
    Location
    Somewhere
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date issue

    I have a situation where I have 2 form fields. One called begin_date and one recon_date. I need to somehow after a date has been filled into the begin_date field to automatically populate that date + 1 year and display it in the recon field automatically....please help.

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a real basic example. Feel free to provide more detail.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Test</title>
    <meta name="Generator" content="TextPad 4.4" />
    <meta name="Author" content="Peter Bailey" />
    <script type="text/javascript">
    function doDate( fromElem, toElem )
    {
    	var d = new Date( fromElem.value );
    	if ( isNaN( d ) )
    	{
    		alert( "Not a valid date" );
    		return;
    	}
    	d.setFullYear( d.getFullYear() + 1 );
    	toElem.value = ( d.getMonth() + 1 ) + "/" + d.getDate() + "/" + d.getFullYear();
    }
    </script>
     
    </head>
    <body>
    <form>
    	Date 1 <input type="text" name="begin_date" value="" onblur="doDate( this, this.form.recon_date )" /><br />
    	Date 2 <input type="text" name="recon_date" value="" readonly="true" />
    </form>
    </body>
    </html>
    Last edited by beetle; Mar 25, 2003 at 14:41.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Member
    Join Date
    Feb 2003
    Location
    Somewhere
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    perfect, but one more thing

    This is perfect, but there is one slight problem. The original date is really coming from a popup so the onblur part doesn't work, what else should work?

    Quote Originally Posted by beetle
    Here's a real basic example. Feel free to provide more detail.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Test</title>
    <meta name="Generator" content="TextPad 4.4" />
    <meta name="Author" content="Peter Bailey" />
    <script type="text/javascript">
    function doDate( fromElem, toElem )
    {
    	var d = new Date( fromElem.value );
    	if ( isNaN( d ) )
    	{
    		alert( "Not a valid date" );
    		return;
    	}
    	d.setFullYear( d.getFullYear() + 1 );
    	toElem.value = ( d.getMonth() + 1 ) + "/" + d.getDate() + "/" + d.getFullYear();
    }
    </script>
     
    </head>
    <body>
    <form>
    	Date 1 <input type="text" name="begin_date" value="" onblur="doDate( this, this.form.recon_date )" /><br />
    	Date 2 <input type="text" name="recon_date" value="" readonly="true" />
    </form>
    </body>
    </html>

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, try onchange in place of onblur
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •