Jump to content

Javascript For Onchange For Ten Days Ago


Recommended Posts

Hello all,

 

I am currently working on a search form (using a virtual field submission form) that has a dropdown menu to select from predefined reports.

 

The way I would like this to function is that when the user selects an option (such as "Recent (Within the Last 10 Days)") an onchange function would change the search fields to the input needed to produce those results.

 

I am fairly new to JavaScript, here is what I have been able to get:

 

<SCRIPT LANGUAGE="JavaScript">
function ocPredefinedReports() {
if (document.getElementById("cbParamVirtual8").value=='Recent (Within the last 10 days)')
   {
    document.getElementById("cbParamVirtual5").value= 'Doe';
   }
}
document.getElementById("cbParamVirtual8").onchange=ocPredefinedReports;</script>​
 

 

 

Through Google-Fu I was able to get a function working at one point that gave me ten days ago (Unfortunately I didn't save it anywhere!) but it was in the wrong format entirely.

 

Any and all help is much appreciated, thank you.

 

 

-Blue

 

Edit: Sorry about the terrible title, time for more coffee. 

Link to comment
Share on other sites

Hello DataCobalt,

 

If I understand you correctly, you can use the following code:

<SCRIPT LANGUAGE="JavaScript">
function ocPredefinedReports() {
if (document.getElementById("cbParamVirtual1").value=='Recent (Within the last 10 days)')
   {
   var nDate = new Date();
   var new_date = new Date(nDate.setDate(nDate.getDate()-10));
   var d_month = new_date.getMonth() + 1;
   if (d_month<10) {d_month = "0" + d_month;}
   var d_day = new_date.getDate();
   if (d_day<10) {d_day = "0" + d_day;}
   var d_year = new_date.getFullYear();
   var str_date = d_month + "/" +  d_day + "/" + d_year;
   document.getElementById("cbParamVirtual2").value=str_date;    
   }
else
{document.getElementById("cbParamVirtual2").value="";}
}
document.getElementById("cbParamVirtual1").onchange=ocPredefinedReports;
</SCRIPT>

Does it work for you?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...