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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create date based on +### string 1

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
I need a script where I can create a date based on a given string. The string is expected to be something like

+###

Where the + sign tells the script to add and ### is the number of days from today.

So, if user typed +2 on a field, onBur will call the JS script/function passing this.value. The JS script should check for + to be 1st character - If there, the field should be populated with the date after adding ### days to current date.

So, +2 should result on 04/10/08 since today's date is 04/08/08.

I can write this in PHP but I do not know enough JS - Hope you guys can help me here.

Thanks!




 
consider this:
Code:
var d=new Date();
d.setDate(d.getDate()+30)
alert(d)
Where instead of "30" you could have the number parsed from your string:
Code:
var strIn = "+021"
alert(parseInt(strIn,10))

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top