homepage Welcome to WebmasterWorld Guest from 54.227.182.191
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript button to insert/add to a form field.
Woz




msg:1472062
 8:39 am on Mar 12, 2002 (gmt 0)

I have a page with a form that contains information to be entered into a database. One field is a date field which automatically retrieves the stored date, or, if no date stored enters today's date, when the form is loaded.

I would like to have a couple of buttons, which I am assuming will need javascript, to allow the user to
Button 1) replace the field contents with the date x days later than the current field contents, or
Button 2) replace the field contents with the date x days from today.

For the purpose of the exercise, lets assume x = 7 days.

Wondering if anyone can give me any pointers on how to do this as I don't know much Javascript. Also, what would be the difference in coding between replacing the field contents or adding to the current field contents in, say, a text field.

(sounds a bit like an exam question 'ey?)

Onya
Woz

 

isNaN




msg:1472063
 3:10 pm on Mar 12, 2002 (gmt 0)

I hope this is what u r looking for

Post the following script in the <head> tag.

<script type="text/javascript">
function getAssignDate( when )
{
var x = 7;
mydate = new Date();
mymonth = mydate.getMonth();
myweekday = mydate.getDate();
myyear = mydate.getYear();
if (myyear < 1000) myyear += 1900;
months = new Array ("January","February","March","April","May","June","July","August","September","October","November","December");//define arrays
var toThisField = document.myForm.thisDate;
if( 'newDate' == when )
{
toThisField.value = months[mymonth] + " " + new Number( myweekday + x ) + ", " + myyear;

}
else
toThisField.value = months[mymonth] + " " + myweekday + ", " + myyear;

}
</script>
And this in the <html>
<body onload="getAssignDate( 'today' )">

<form name="myForm">
<input type="text" name="thisDate" value="" />
<input type="button" value="Click to enter new date" onclick="getAssignDate( 'newDate' );" />
</form>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved