By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,385 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,385 IT Pros & Developers. It's quick & easy.

From Date/To Date Issue

Stang02GT
Expert 100+
P: 1,208
Here is the issue that I am having. I have two text feilds where users need to enter a "From Date:" and a "To Date:" they then hit a update button and my code will pull back the data for the date ranges they have selected.

If the user enters the same date in both from and to fields they are expecting to see just one row returned for that day, BUT what is really happening is it is returning all the data.

Does anyone have any suggestions or ideas on how I can just have one row return if the users enter the same date?


Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language="javascript">
  2.  
  3. function submit() {
  4.  
  5.     var fundshareid = document.getElementById('fundshareid').value;
  6.     var fd = document.getElementById('fd').value;
  7.     var td = document.getElementById('td').value;
  8.  
  9.     var tp = "<%=request.getParameter("tp")%>";
  10.  
  11.     if (tp == null || tp == "null") {tp = "fl";}
  12.  
  13.     return document.location = "<%=request.getAttribute("baseURI")%>" + "?fd=" + fd + "&fundshareid=" + fundshareid + "&link=products&td=" + td + "&tp=" + tp + "&ut=" + "<%=request.getParameter("ut")%>";
  14.  
  15. }
  16.  
  17. function validate(){
  18.  
  19.     if (isDate(document.forms[1].fd.value)==false){
  20.         document.forms[1].fd.focus();
  21.         return false;
  22.     }
  23.     if (isDate(document.forms[1].td.value)==false){
  24.         document.forms[1].td.focus();
  25.         return false;
  26.     } else {
  27.         fd = new Date(document.forms[1].fd.value);
  28.         td = new Date(document.forms[1].td.value);
  29.         if (fd > td){
  30.             alert("We're sorry, but we are unable to display the requested data.  Please select a \"To Date\" that is greater (more recent) than the \"From Date.\"");
  31.             return false;
  32.         }
  33.     }
  34.  
  35. return true;
  36. }
Aug 7 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
You don't need a submit() function to do this job for you when you can just let the browser pass the values in the correct format. If you use this format:
Expand|Select|Wrap|Line Numbers
  1. <form ... onsubmit="return validate()">
then the form will submit if validate() returns true. If you need extra values, add some hidden values.
Aug 7 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.