Link to home
Start Free TrialLog in
Avatar of benpung
benpung

asked on

Post value to text box

I have a html form that has two text boxes.  one takes the start date, one takes the end date.  when i click the submit button i'm calling the below javascript function.  the function accepts the start and end dates as params, compares them, and if the start date is after the end date, alerts the user that they screwed up.  this all works fine. my problem is that after i click "ok" on the alert box, both start and end date text boxes go back to being blank.  i want to preserve the values that were entered (i.e. popluate the text boxes with a and b), and set the focus back to the start date so the user can adjust it.  how can i do this?

function start_end_date(a,b){
var start_dt = new Date (a);
var end_dt = new Date (b);
if (a > b) {
alert ("start date is greater than end date");
}
}
Avatar of archrajan
archrajan

unction start_end_date(a,b){
var start_dt = new Date (a);
var end_dt = new Date (b);
if (a > b) {
alert ("start date is greater than end date");
a.focus();
a.select();
}
}
Avatar of benpung

ASKER

after i click "OK" on the alert box, I get the error "object doesn't support this property or method".  here is the entire page:


<html><head><title>This is a play page</title>
<script language = "Javascript">

function start_end_date(a,b){
var start_dt = new Date (a);
var end_dt = new Date (b);
if (a > b) {
alert ("start date is greater than end date");
a.focus();
a.select();
}
}

</script>
</head>
<body>
<form name="frmSample" method="post" action="" onSubmit="start_end_date(this.start_date.value, this.end_date.value)">
                <p>Enter Start Date <font color="#CC0000"><b>(mm/dd/yyyy)</b></font>
                  :
                  <input type="text" name="start_date" maxlength="10" size="15">
                </p>
<br>
                <p>Enter End Date <font color="#CC0000"><b>(mm/dd/yyyy)</b></font>
                  :
                  <input type="text" name="end_date" maxlength="10" size="15">
                </p>
<br>
                <p>
                  <input type="submit" name="Submit" value="Submit">
                </p>
              </form>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of archrajan
archrajan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of benpung

ASKER

yup, that's what i needed!  thanks.