DataCobalt 10 Report post Posted February 3, 2015 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. Quote Share this post Link to post Share on other sites
Jan 51 Report post Posted February 3, 2015 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? Quote Share this post Link to post Share on other sites
DataCobalt 10 Report post Posted February 3, 2015 Worked like a charm. Thank you again for all of your JavaScript mastery Jan! Quote Share this post Link to post Share on other sites
Jan 51 Report post Posted February 4, 2015 You are very welcome! Quote Share this post Link to post Share on other sites