Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function Help 2

Status
Not open for further replies.

mdr2273

Programmer
Sep 4, 2006
22
US
I am new to Javascript. Can someone help with the following? I would like the text box txtDate to be set to the current date and the text box txtAmount set to 0 when a user clicks on the checkbox txtChkBox1. The simple HTML code is below.

Thank you!


<input type="checkbox" name="txtChkBox1" /> Click Here<br />
<input type="text" name="txtDate" /><br />
<input type="text" name="txtAmount" /><br />
 
<input type="checkbox" name="txtChkBox1" onclick="txtDate.value=new Date(); txtAmount.value=0;" />

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Thank you. How would I format the date to read 1/3/07 in that format?
 
you would need to break it out to a function and into its parts....
Code:
function formatDate(obj){

var dte = new Date();

var myMonth = dte.getMonth()+1;
var myDay = dte.getDate();
var myYear = dte.getFullYear();

var mydate = '' + myday + '/' + mymonth + '/' + myyear;

obj.value = mydate;
}

if you want just 2 digit year you could apply a sub string command to grab just the last two digits.

and remember you will need to call it as follows now because you pass it the object to be updated.

<input type="checkbox" name="txtChkBox1" onclick=" txtAmount.value=0; formatDate(txtDate);" />



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
oops made typo's remember those var names should be
Code:
var mydate = '' + myDay + '/' + myMonth + '/' + myYear;
pesky case sensetive is JS

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
mdr2273, since you've posted a handful of threads to the site now and have become familiar with it, why not try awarding a star to 1DMF for the help he provided you? It's a nice way to show appreciation to others that put forth the effort to help you with your problems, and it gives them a vote for the tipmaster of the week. You can click the "Thank 1DMF for this valuable post" link on any of his replies to submit a vote for him.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
ahh, why thank you kaht, didn't know you cared [gorgeous]

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
You never know, I might be the one to answer his question next time. [wink]

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
oic alterior motive , you could always give me the star your self hun :)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
But that doesn't get those who ask questions into the habit of responding properly.

Lee
 
Thanks for pointing that option out, I have given 1DMF a star. I didn't know that was an option until just now.
 
I didn't know that was an option until just now.

Some people just need a subtle nudge in the right direction [thumbsup2]

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
glad i could help mdr2273 , it's normally the other way round :p

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top