kme Posted March 31, 2014 Report Share Posted March 31, 2014 Hello, In a table, there is a field (field 1) for selecting "Y" or "N", and default is set to N. However, I'd like another field (field 2) for a timestamp when it is updated to "Y". So, somehow field 2 should be connected to field 1, and I've written the following function so far for field 2 through a Data Page: CASE WHEN [@field:NEF_Plan_of_Execution_Material_Support_Required] = 'Y' THEN GetUTCDate() END But it's not getting the timestamp for the exact time when field 1 was clicked "Y"; it's just getting the current server time. Also, when creating a field in a table and assigning a DataType to it, there's an option for "Timestamp" and at the bottom some additional options for "Stamp on Insert" and "Stamp on Update", but there isn't a way to make it tie to another field. How should I go about completing this task of making field 2 a timestamp for when field 1 is updated to Y? Thank you so much Quote Link to comment Share on other sites More sharing options...
MayMusic Posted March 31, 2014 Report Share Posted March 31, 2014 You can use this javascript to call a function to assign date when a checkbox is checked. Make sure to replace the IDs with corresponding IDs. <script> document.getElementById('ID OF CHECKBOX').onchange = function () { if (document.getElementById('ID OF CHECKBOX').checked){ var currentdate = new Date(); var datetime = currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds(); document.getElementById('ID OF DATE FIELD').value = datetime; } } </script> Quote Link to comment Share on other sites More sharing options...
kme Posted March 31, 2014 Author Report Share Posted March 31, 2014 Thanks for the reply. I added this to the "Footer" section of details page on DataPage: <script> document.getElementById('SupportReady').onchange = function() { if (document.getElementById('SupportReady').checked){ var currentdate = new Date(); var datetime = currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds(); document.getElementById('Timestamp').value = datetime; } } </script> It doesn't seem to be working. One concern I have is the part where it says "checked" - I'm wondering if it knows what it is checked to. How about if I do something like value=="Y"? This is the code I have so far based off of info I got from caspio forums but it also isn't working: <script> function myFunction() { var v = document.getElementById("SupportReady").value; if (v=='Y'){ document.getElementById("Timestamp").value = "[@cbTimestamp]"; } document.getElementById("caspioform").onsubmit=myFunction; </script> This is a Report DataPage. When clicking on details, "SupportReady" has radio buttons with 2 options Display:YES, Value:Y, and Display:NO, Value:N. Default value is N, and when it's updated to Y I want the field "Timestamp" to have a timestamp. In Tables, SupportReady has DataType of "Text(255)". Quote Link to comment Share on other sites More sharing options...
MayMusic Posted March 31, 2014 Report Share Posted March 31, 2014 document.getElementById('SupportReady').checked should work if you have a checkbox, place the code in an HTML Block after both checkbox and date field. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted March 31, 2014 Report Share Posted March 31, 2014 Also in my code I intended to call the function onchange not submit. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted March 31, 2014 Report Share Posted March 31, 2014 Now that you have radio buttons if the yes option is the first option try this code in an HTML Block at the end of element list: <script> document.getElementById('EditRecordSupportReady0').onclick= function () { if (document.getElementById('EditRecordSupportReady0').value == 'Y'){ var currentdate = new Date(); var datetime = currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds(); document.getElementById('Timestamp').value = datetime; } } </script> This should work. If not working for you provide me the link of the page Quote Link to comment Share on other sites More sharing options...
kme Posted March 31, 2014 Author Report Share Posted March 31, 2014 An HTML Block after radio buttons and timestamp field would create another field - do I add the HTML Block under Results Page or Detail Page? [edited] Quote Link to comment Share on other sites More sharing options...
kme Posted March 31, 2014 Author Report Share Posted March 31, 2014 I'm guessing Details Page, but it still doesn't seem to be working. Here is the link: <http://b4.caspio.com/dp.asp?AppKey=b05320005057b918f4354d1992ba> Quote Link to comment Share on other sites More sharing options...
MayMusic Posted March 31, 2014 Report Share Posted March 31, 2014 Where do you have your data/time field? I do not see any date/time field in your table Quote Link to comment Share on other sites More sharing options...
MayMusic Posted March 31, 2014 Report Share Posted March 31, 2014 I also looked through your hidden field but there is not date field. Make sure it is not a timestamp field in the table since we cannot rewrite on it. It has to be a date field. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted March 31, 2014 Report Share Posted March 31, 2014 And yes, the HTML Block should be in details page Quote Link to comment Share on other sites More sharing options...
kme Posted March 31, 2014 Author Report Share Posted March 31, 2014 On the Results Page, the column "Timestamp" is the field for timestamp. There is no field for "Timestamp" in the details page, although there could be if necessary. I'm wondering how the code could specify what's shown on Details Page and what's shown on Results Page. In the Tables, I changed the datatype for the "Timestamp" field to Date/Time when it used to be Text(255), but it doesn't seem to be working. Is the code saying that the field "Timestamp" will be changed as soon as "Y" is clicked? How about doing the function when the update button is clicked, or something like document.getElementById("caspioform").onsubmit=myFunction; ? Quote Link to comment Share on other sites More sharing options...
kme Posted March 31, 2014 Author Report Share Posted March 31, 2014 I tried this: <script> function myFunction() { if (document.getElementById('EditRecordSupportReady0').value == 'Y'){ var currentdate = new Date(); var datetime = "Last Sync: " + currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds(); document.getElementById('Timestamp').value = datetime; } } document.getElementById("caspioform").onsubmit=myFunction(); </script> But it's also not doing it.. I've tried adding it in Footer section, I've tweaked with changing it to ('EditRecordSupportReady')[0], etc. but it doesn't seem to be working... Here are some extra info just in case: Tables SupportReady = Text(255) Timestamp = Date/Time DataPage - Report Results Page SupportReady = Render value as: Text, Formatting: None Timestamp = Formatting: None Details Page SupportReady = Radio buttons HTML Block = where code inputted Anyone have any ideas? Quote Link to comment Share on other sites More sharing options...
MayMusic Posted March 31, 2014 Report Share Posted March 31, 2014 You do not need to change the format since I had it work in my account. Make sure Timestamp filed is included in the details page as well. I am still not seeing this field. The issue should be this line: document.getElementById('Timestamp').value = datetime; The Timestamp need to be replaced with the correct ID. Is the field name is Timestamp in the table it needs to be included in the details page and the ID would be EditRecordTimestamp You can call the function onsubmit as well. Quote Link to comment Share on other sites More sharing options...
kme Posted April 1, 2014 Author Report Share Posted April 1, 2014 I changed the line to document.getElementById('EditRecordTimestamp').value=datetime; and the Timestamp field is included in the Details Page. But it's not working... Thanks so much for your help so far by the way - I can't thank you enough. Quote Link to comment Share on other sites More sharing options...
kme Posted April 2, 2014 Author Report Share Posted April 2, 2014 I would really appreciate any feedback on this - Here are some other forum threads very similar to this. http://forums.caspio.com/index.php/topic/3488-time-stamp-field-based-on-selection-in-drop-down/ http://forums.caspio.com/index.php/topic/3547-if-then-and-else-for-timestamp/ http://forums.caspio.com/index.php/topic/3567-how-do-you-timestamp-when-the-checkbox-is-checked/ I've tried their code as well, and changing my SupportReady to checkbox, dropdown, etc. and changing the DataType around, but it doesn't seem to be working. Thoughts? This should be relatively simple. Thanks so much Quote Link to comment Share on other sites More sharing options...
kme Posted April 2, 2014 Author Report Share Posted April 2, 2014 MayMusic - Thanks so much, it is working now. For those interested in the solution, The additional problem was that Timestamp field in the Table had to have a datatype of Text(255). In the Details Page, Timestamp was changed to a Text Field. Once Yes was clicked, the textfield was filled with a timestamp, and then when Update was clicked, the field in the Results Page was filled with the timestamp. Thanks again. MayMusic, jonathanr, wayancenik and 1 other 4 Quote Link to comment Share on other sites More sharing options...
MayMusic Posted April 3, 2014 Report Share Posted April 3, 2014 You are very welcome!!! :) :) Quote Link to comment Share on other sites More sharing options...
pavitra2410 Posted April 11, 2014 Report Share Posted April 11, 2014 To make the field non-editable, add this to your JavaScript document.getElementById('EditRecordSupportRequiredYes').disabled= true; document.getElementById('EditRecordSupportReadyYes').disabled= true; kme 1 Quote Link to comment Share on other sites More sharing options...
MayMusic Posted April 11, 2014 Report Share Posted April 11, 2014 <script> var currentdate = new Date(); var datetime = currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds(); document.getElementById('EditRecordSupportReady0').onclick= function () { if (document.getElementById('EditRecordSupportReady0').value == 'Y'){ document.getElementById('EditRecordSupportRequiredYes').value = datetime; document.getElementById('EditRecordSupportRequiredYes').disabled= true; } else if (document.getElementById('EditRecordSupportReady1').value == 'Y') { document.getElementById('EditRecordSupportRequiredYes').value = "" ; } } document.getElementById('EditRecordSupportReady0').onclick= function () { if (document.getElementById('EditRecordSupportReady0').value == 'Y'){ document.getElementById('EditRecordSupportReadyYes').value = datetime; document.getElementById('EditRecordSupportReadyYes').disabled= true; } else if (document.getElementById('EditRecordSupportReady1').value == 'Y') { document.getElementById('EditRecordSupportReadyYes').value = "" ; } } </script> This code should make the visible text field disabled so user cannot change and also to remove the value from hidden text field since if user selects Yes first the date will appear on text field and now if checks no the field is hidden but the value is there so we need to remove the value now I have not tested the code but it should work kme 1 Quote Link to comment Share on other sites More sharing options...
kme Posted April 11, 2014 Author Report Share Posted April 11, 2014 Thank you so much, the fields are non-editable and everything is working now. Here is my code: <script> document.getElementById('EditRecordSupportReadyYes').disabled= true; document.getElementById('EditRecordSupportRequiredYes').disabled= true; document.getElementById('EditRecordSupportRequired0').onclick= function () { if (document.getElementById('EditRecordSupportRequired0').value == 'Y'){ var currentdate = new Date(); var datetime = (currentdate.getMonth()+1) + "/" + currentdate.getDate() + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes(); document.getElementById('EditRecordSupportRequiredYes').disabled= false; document.getElementById('EditRecordSupportRequiredYes').value = datetime; document.getElementById('EditRecordSupportRequiredYes').disabled= true; } } document.getElementById('EditRecordSupportRequired1').onclick= function () { if (document.getElementById('EditRecordSupportRequired1').value == 'N'){ document.getElementById('EditRecordSupportRequiredYes').disabled= false; document.getElementById('EditRecordSupportRequiredYes').value = ""; document.getElementById('EditRecordSupportRequiredYes').disabled= true; } } document.getElementById('EditRecordSupportReady0').onclick= function () { if (document.getElementById('EditRecordSupportReady0').value == 'Y'){ var currentdate = new Date(); var datetime = (currentdate.getMonth()+1) + "/" + currentdate.getDate() + "/" + currentdate.getFullYear() + " " + currentdate.getHours() + ":" + currentdate.getMinutes(); document.getElementById('EditRecordSupportRequiredYes').disabled= false; document.getElementById('EditRecordSupportReadyYes').value = datetime; document.getElementById('EditRecordSupportReadyYes').disabled= true; } } document.getElementById('EditRecordSupportReady1').onclick= function () { if (document.getElementById('EditRecordSupportReady1').value == 'N'){ document.getElementById('EditRecordSupportRequiredYes').disabled= false; document.getElementById('EditRecordSupportReadyYes').value = ""; document.getElementById('EditRecordSupportReadyYes').disabled= true; } } function enableElements(){ document.getElementById('EditRecordSupportRequiredYes').disabled= false; document.getElementById('EditRecordSupportReadyYes').disabled= false; } document.getElementById("caspioform").onsubmit=enableElements; </script> I had to add the function at the end and extra .disabled lines everywhere because initially the .disabled made it so that when I clicked Update, the timestamps wouldn't show. =) Thanks again. Quote Link to comment Share on other sites More sharing options...
Jarmizee Posted March 12 Report Share Posted March 12 Tried MayMusic's script it works good, but im trying to do multiple radio buttons to enter timestamp into another date feild example start monitoring, contacted local attendant, attendant responded and end monitoring. Each to have its radio button to stamp the time. I revised the code to respond accordingly but each radio button updates the time stamp on all date/time fields. I hope Caspio can do what we are hoping for. Thanks. 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.