Saturday, March 31, 2012

Simple .NET code to JS.

I have a textbox called txtDate.
I have some .NET code:

Private Sub IncrementDate(ByVal DayCount As Integer)

Dim CurrentDate As Date = Date.Parse(txtDate.Text)
Dim NewDate As Date = CurrentDate.AddDays(DayCount)

txtDate.Text = NewDate.ToString("dd MMM yyyy")

End Sub

What I would like is this to be in JS.
Any ideas?

WokaCreate a new page with this code in it, then you'll get an idea of how it works. I'm currently incrementing the date value by 4. I chose 4 for no specific reason.

<html>
<head><title>Woka's best page ever</title>
<script language="JavaScript">

function filltxtdate(datevalue, intDaysToAdd){

var initialdate = new Date(datevalue);
var newdate = new Date(initialdate.getFullYear(),initialdate.getMonth(), initialdate.getDate() + intDaysToAdd);

document.getElementById('txtdate').value = outputFormat(newdate);

}

function outputFormat(obj) {

var DA = new String("JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC");
var passedDate = obj;

var M3 = 3 * passedDate.getMonth();
alert(passedDate.getDate());
return passedDate.getFullYear() + " " + DA.substring(M3, M3+3) + " " + padabit(passedDate.getDate());

}

function padabit(x) { return (x>=10||x<0?"":"0") + x }

</script>

</head>
<body>
<form id="form1" name="form1">
<input type="text" id="txtdate" name="txtdate">
<input type="button" onClick="javascript:filltxtdate(document.getElementById('txtdate').value, 4);" value="Click">
</form>
</body>
</html>
thnaks. woof
Add resolved?

0 comments:

Post a Comment