Click to See Complete Forum and Search --> : filling in a textbox


EyeTalion
02-05-2003, 08:34 AM
I need to fill in a textbox with a date of one day greater then the date the user puts in another textbox. The textbox can also stay empty, so I'll need to check if data was placed in. I'm writing this in ASP.NET, the code below works fine to add a date one day greater then what the user selected, but I need to place it in a javascript, so the code runs on the client side...I'm new to javascript, can some give me an example....thanks





'txtIntDisEndDate.Text = DateAdd(DateInterval.Day, 1, CDate(txtBidOpenDate.Text))

Charles
02-05-2003, 12:35 PM
Keeping in mind that JavaScript will fail one in ten times, it is important to keep your server side validation. But it's a nice touch to have it client side as well to save 90% of your users an HTTP request.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Date example</title>

<script type="text/javascript">
<!--
Date.SECOND = 1000;
Date.MINUTE = Date.SECOND * 60;
Date.HOUR = Date.MINUTE * 60;
Date.DAY = Date.HOUR * 24;

Date.prototype.toString = function () {return [this.getDate(), ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] [this.getMonth()], this.getFullYear()].join(' ')}
// -->
</script>

<form action="someScript.pl">
<div><input type="text" name="firstDate" onchange="var d = new Date(this.value); if (isNaN(d.valueOf())) {alert('Need a real date'); this.value=''; this.focus()} else {this.value = d; document.forms[0].secondDate.value=new Date(d.getTime() + Date.DAY)}"></div>
<div><input type="text" name="secondDate"></div>
<div><input type="submit"></div>
</form>

And see http://developer.netscape.com/docs/manuals/js/client/jsref/date.htm for details concerning the JavaScript Date object.