We help IT Professionals succeed at work.
Get Started

Javascript Add variable # Days to Calendar then populate field

703 Views
Last Modified: 2013-11-18
I have a Great handling idea for a user experience that needs to calculate EXACTLY 30 days from any given date, but though I know Im close, I cannot figure out whats NOT working...

If I populate one form input field with todays date so a user can change it if need-be,
then when they go to click the dropdown to extend that date. The script should grab the original date "origdate" and onChange of the drop down go perform the calculation of the selected number of days and add that to the original date then populate the changed extended date "edate" before pressing UPDATE btn to continue.


thanks so much


P.S. please do not introduce/suggest a bulky javascript framework -- not my idea of working it out w/ DOM. thanks so much!!
<script type="text/javascript">
function setRetention(duration) { 
	var lengthRetention = ""; 
	var newAssignment = ""; 
	var tempOrigDate = ""; 
  if (duration.selectedIndex>0) { // e.g. not the "Select Option"
     //works
     lengthRetention += duration.options[duration.selectedIndex].value;
     
     // not too sure if functioning right...
     tempOrigDate += document.forms[0].origdate.value;
     // or tempOrigDate += document.getElementsById('cdate').value;
     // think its failing cause maybe Im not handling data-types correctly      
     tempOrigDate.setDate(tempOrigDate.getDate()+lengthRetention);
     // adding this way makes sense right? integer 30 days + to date right?
     
  }
   // then I want to push that new calculated value to a display form field
  duration.form.edate.value=newAssignment;
}
</script>



<%
' ASP.Net code 
today = month(now) & "/" & day(now) & "/" & year(now)
Response.Write "<form name='edit' action='writetodb.asp' method='post'>"
'
Response.Write "Original Date: <input name=""origdate"" id=""origdate"" type=""text"" value='" & today & "'>"
'
Response.Write "Assign an extended Date:<br>"
Response.Write "<select name=""retention"" id=""retention"" onChange=""setRetention(this)"">"
Response.Write "<option selected=""selected"">Select an Extension Length</option>"
Response.Write "<option value=""30"";>30 days Active</option>"
Response.Write "<option value=""14"";>14 days Active</option>"
Response.Write "</select><br>"
'
Response.Write "Expiration Date: <br>"
'
' The Revised Date should populate and be displayed in this input field::.
Response.Write "<input type=""text"" name=""edate"" id=""edate"">"
'
Response.Write "<input type=submit value='UPDATE'>"
'
%>
</form>

Open in new window

Comment
Watch Question
IT Expert
CERTIFIED EXPERT
Top Expert 2009
Commented:
This problem has been solved!
Unlock 4 Answers and 18 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE