Solved

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

Posted on 2009-03-30
9
299 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now