?
Solved

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

Posted on 2009-03-30
9
Medium Priority
?
306 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

719 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