Solved

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

Posted on 2009-03-30
9
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

621 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