caspiouser22 Posted March 6, 2012 Report Share Posted March 6, 2012 I have a date/time field. Caspio has the option to search from NOW onwards. I would like to search from 1 hour before now onwards. I could use Javascript to determine the current time and subtract an hour. Then add this to the Equal and Greater to form. 1) How can you add HTML to the filter page on datapage? 2) How can I tell Javascript to populate a criteria field of a field This is the Javascript I have to determine the current date/time. I just need to finish it and get the two above questions and remove one hour from the time (I'm currently cheating and just showing the current hour) Any help appreciated. Elliot <script type="text/javascript"> /* Declaration and initialization */ Stamp = new Date(); var v_TimeStamp; Hours = Stamp.getHours() Mins = Stamp.getMinutes(); /* Attach a prefix with digit '0' if the minutes is less than 10. */ if (Mins < 10) { Mins = "0" + Mins; } /* Construct the value of the v_TimeStamp variable in the format m/d/yyyy hh:mm */ v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear() + ' ' + Hours + ":00"); /* Field name - TimeofView is referred with a prefix - EditRecord */ var v_drop = document.getElementsByName("InsertRecordburst_date")[0]; if (v_drop) { var new_option = document.createElement('option'); new_option.value = v_TimeStamp; new_option.text = v_TimeStamp; new_option.selected = true; try { v_drop.add(new_option,null); }catch(v_ex){} } </script> Quote Link to comment Share on other sites More sharing options...
HongTaiLang Posted March 7, 2012 Report Share Posted March 7, 2012 If you want to search the time after one hour before system time, select the time field from available fields at first. On the Configure Search Fields, you can select "Greater Than or Equal" from Comparison type and select "Date and Time" from Precision. Insert following code to Header : <SCRIPT LANGUAGE="JavaScript"> function newTime() { /* Declaration and initialization */ Stamp = new Date(); var v_TimeStamp; Hours = Stamp.getHours() - 1; //get one hour earlier than present time Mins = Stamp.getMinutes(); /* Attach a prefix with digit '0' if the minutes is less than 10. */ if (Mins < 10) { Mins = "0" + Mins; } /* Construct the value of the v_TimeStamp variable in the format m/d/yyyy hh:mm */ v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear() + ' ' + Hours + ":" + Mins); document.getElementById("Value1_1").value = v_TimeStamp; //Set Time field } window.onload = newTime; </SCRIPT>"Value1_1" in the code is the id of time field. Please replace it to a correct one.The time field in you search page will be equal to one hour earlier than present time. Quote Link to comment Share on other sites More sharing options...
caspiouser22 Posted March 7, 2012 Author Report Share Posted March 7, 2012 Many thanks for your reply. One additional question I've come across. I am using criteria on the date/time field as well. Any idea how I populate criteria 3 of a certain field? Thanks Quote Link to comment Share on other sites More sharing options...
caspiouser22 Posted March 7, 2012 Author Report Share Posted March 7, 2012 Also - no headers in the filtering fields page - any thoughts? Thanks again Quote Link to comment Share on other sites More sharing options...
HongTaiLang Posted March 8, 2012 Report Share Posted March 8, 2012 Sorry, my method is not based on filtering data based on pre-defined criteria. You can have regular search, and make to submit the search automatically. Here is the code: function newTime() { /* Declaration and initialization */ Stamp = new Date(); var v_TimeStamp; Hours = Stamp.getHours() - 1; //get one hour earlier than present time Mins = Stamp.getMinutes(); /* Attach a prefix with digit '0' if the minutes is less than 10. */ if (Mins < 10) { Mins = "0" + Mins; } /* Construct the value of the v_TimeStamp variable in the format m/d/yyyy hh:mm */ v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear() + ' ' + Hours + ":" + Mins); document.getElementById("Value1_1").value = v_TimeStamp; //Set Time field } function f_submit() { document.getElementById("caspioform").submit(); } window.onload = function() { newTime() ; f_submit(); } alexm72 1 Quote Link to comment Share on other sites More sharing options...
caspiouser22 Posted March 8, 2012 Author Report Share Posted March 8, 2012 I had an email response and here are some things cleared up by the helpful guys at Caspio: Value1_2 = Criteria2 I used a search page (not predefined ) and then auto submitted with the following: window.setTimeout('document.getElementById("caspioform").submit()',500); I also had to change the code as it was giving me a 0 numbers (eg. 1 hour before 00:20 should be 23:20 but it was giving me -1:20...) <SCRIPT LANGUAGE="JavaScript"> function newTime() { /* Declaration and initialization */ var olddate = new Date(); // create current date var subbed = new Date(olddate - 2*60*60*1000); // subtract 2 hours var v_TimeStamp; Hours = subbed.getHours(); Mins = subbed.getMinutes(); /* Attach a prefix with digit '0' if the minutes is less than 10. */ if (Mins < 10) { Mins = "0" + Mins; } /* Construct the value of the v_TimeStamp variable in the format m/d/yyyy hh:mm */ v_TimeStamp=(''+subbed.getDate()+ "/" + (subbed.getMonth() + 1) +"/"+subbed.getFullYear() + ' ' + Hours + ":" + Mins); document.getElementById("Value1_2").value = v_TimeStamp; //Set Time field } window.onload = newTime; window.setTimeout('document.getElementById("caspioform").submit()',500); </SCRIPT> I also had to switch the date format around so it played well with UK date format. Hope that helps other stoo - thanks to Caspio for the help too Quote Link to comment Share on other sites More sharing options...
HongTaiLang Posted March 8, 2012 Report Share Posted March 8, 2012 That's really nice. Good for sharing. Thank you. Quote Link to comment Share on other sites More sharing options...
HongTaiLang Posted March 8, 2012 Report Share Posted March 8, 2012 I just found this is a short method to get the timestamp in JS. It is [@cb:Timestamp]. For example: document.getElementById("InsertRecordFileName").value="[@cbTimestamp]"; Quote Link to comment Share on other sites More sharing options...
caspiouser22 Posted March 8, 2012 Author Report Share Posted March 8, 2012 Thats a nifty variable. It works in caspio too as a parameter. I really wanted to use it in the predefined search parameters page but couldn't work out how to apply logic to it. IE. [@cbTimestamp] - 1hour The way I'm auto-submitting a search page is a bit naff. I'm developing a mobile app and on loading it has to run the client-side javascript first. It would be much much better if I could use the predfined page and add some logic with the above code than o it all in Javascript - if you have any ideas I'd be dead chuffed to hear them. Cheers Quote Link to comment Share on other sites More sharing options...
caspiouser22 Posted March 8, 2012 Author Report Share Posted March 8, 2012 ie. [@cbTimestamp]-01:00:00 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.