Solved

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

Posted on 2009-03-30
9
300 Views
Last Modified: 2012-05-06
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
Comment
Question by:henriqmib
9 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 24020010
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
 

Author Comment

by:henriqmib
ID: 24020054
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
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 24033294
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 63

Expert Comment

by:Zvonko
ID: 24033392
What is the format of the date in the first input box? MM/DD/YYYY???
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 24033485
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
 

Author Closing Comment

by:henriqmib
ID: 31564362
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 24041369
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question