• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

How do I dynamically update textboxes on a page if a textbox value is changed (using vbscript)?

Hello

I have an ASP form with 2 textboxes for date fields. If the one date field is completed, it needs to automatically update the other textboxes: the second textbox must be updated to a date 1 day less than the date in the first textbox.

I would prefer to use vbscript, but will use javascript if this is the better solution. Please can you help with this query.

Thanks
M
0
henriqmib
Asked:
henriqmib
1 Solution
 
aprestoCommented:
It all depends. You can use VBScript if you dont mind the page being submitted. But i would suggest Javascript because you can do it without the page going anywhere.
Which one would you like to use?
0
 
henriqmibAuthor Commented:
Oh - I thought you could use VBScript without submitting the page?

Either one is fine as long as it works. I definitely want to do it on the page prior to submitting.
0
 
Carl TawnSystems and Integration DeveloperCommented:
You can use VBScript but that will limit your code to Internet Explorer. Javascript would be your better option if you need cross-browser compatibility.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZvonkoSystems architectCommented:
What is the format of the date in the first input box? MM/DD/YYYY???
0
 
ZvonkoSystems architectCommented:
Here a basic function:
<script>
function addDays(theField, numDays,fieldName){
  var theDate = new Date(theField.value);
  if(!isNaN(theDate)){
    theDate.setDate(theDate.getDate()+numDays);
    theField.form[fieldName].value = (theDate.getMonth()+1)+'/'+theDate.getDate()+'/'+theDate.getFullYear();
  } else {
    return "";
  }
}
</script>
 
<form>
<input type="text" name="fromDate" onChange="addDays(this,1,'toDate')" >
<input type="text" name="toDate"  >
</form>

Open in new window

0
 
henriqmibAuthor Commented:
Thanks! This is perfect!

Do you know if there is any way to combine javascript on one box. For instance, initially I had this too:
onfocus=showCalendarControl(this);
The 2 functions didn't seem to work together. (I don't know javascript well enough to know what I did wrong).
0
 
ZvonkoSystems architectCommented:
That is really a new question.
And it depends on your showCalendarControl() function.
Basicaly it is always a problem to read selected date AFTER the user clicked on something in the calender control. That is not a sequential action but an asynchronous event.

Please open a new question for that topic.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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