[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1085
  • Last Modified:

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");
}
}
0
benpung
Asked:
benpung
  • 2
  • 2
1 Solution
 
archrajanCommented:
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();
}
}
0
 
benpungAuthor Commented:
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>
0
 
archrajanCommented:
<html><head><title>This is a play page</title>
<script language = "Javascript">

function start_end_date(a,b){
var start_dt = new Date (a.value);
var end_dt = new Date (b.value);

if (start_dt > end_dt) {
alert ("start date is greater than end date");
a.focus();
a.select();
return false;
}
}

</script>
</head>
<body>
<form name="frmSample" method="post" action="" onSubmit="return start_end_date(this.start_date, this.end_date)">
                <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>
0
 
benpungAuthor Commented:
yup, that's what i needed!  thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now