juancoffee Posted September 30, 2013 Report Share Posted September 30, 2013 Hello I'm a bit of a Caspio newbie and pretty unskilled (ok - very unskilled!) at Javascript. I have a couple of, hopefully small, issues that I assume I need some basic javascript to solve. I've tried adapting code that I've found elsewhere, but I don't really know what I'm doing:- 1.I have a field called 'maximum_people' and one called 'no_of_people'.I need to restrict the number of bookings received on a given date, so if I create a report datapage (filtering by date) I need to add up all the 'no_of_people' submissions, and then have the form stop if it >='maximum people'. I suppose I need something like-<script>if(SUM[@field:no_of_people] <[@field:maximum_people]){document.write("<a href='http://b6.caspio.com/dp.asp?AppKey=504f20004a6cefd06ad94881b12c&Course_ID=[@field:Course_ID]'>Signup</a>");}else{document.write("<p>Signup Closed</p>")}</script>2.)The second thing is a simple block to ensure that no bookings are made before today (as the Caspio calendar allows any date to be selected, even in the past)-I guess it is sort of like-<script>if([@field:date] >="today"){document.write("<a href='http://b6.caspio.com/dp.asp?AppKey=504f20004a6cefd06ad94881b12c&Course_ID=[@field:Course_ID]'>Signup</a>");}else{document.write("<p>Sorry, we can only take bookings from tomorrow onwards</p>")}</script> I'm flying blind though, and there are probably 101 better ways to achieve what I need. Hopefully someone can help... Duncan Quote Link to comment Share on other sites More sharing options...
MayMusic Posted October 1, 2013 Report Share Posted October 1, 2013 I am looking into that for you for you here is what I found to compare the date so far: http://stackoverflow.com/questions/13062526/how-to-compare-date-with-todays-date-where-date-is-in-format-dd-mm-yyyy Quote Link to comment Share on other sites More sharing options...
Barbara Posted October 1, 2013 Report Share Posted October 1, 2013 Hi, as for the first one there is a techtip at http://howto.caspio.com/customization/limit-the-number-of-maximum-submissions.html which may help you with what you're trying to achieve. For the second one your logic is correct but you need to define a variable and assign today's value then use that in your comparison. You can capture today's value by using [@cbTimestamp] In either case JavaScript method is not a bullet proof way of limiting submissions. Because JavaScript can easily be manipulated by a technical user as it runs on the browser side. A recommended method is to write a server side program to achieve this. This can be done by Caspio PS team. If you are interested to get a quote you can submit the requirements at http://www.caspio.com/support/professional-services.aspx. Cheers, Barbara Quote Link to comment Share on other sites More sharing options...
MayMusic Posted October 1, 2013 Report Share Posted October 1, 2013 This code can help you to prevent from entering previous dates: <script> function checkdate(){ alert('in'); var sdate = document.getElementById('InsertRecordDATEFIELD').value; if (Date.parse(sdate) < Date.now()) { alert("Choose a date after today"); return false; } } document.getElementById('caspioform').onsubmit=checkdate; </script> Replace "DATEFIELD" with the date field name. And if the code is being used in an update page change InsertRecord to EditRecord. juancoffee 1 Quote Link to comment Share on other sites More sharing options...
juancoffee Posted October 2, 2013 Author Report Share Posted October 2, 2013 That's great - thanks for the help. Your code is great - thanks MayMusic. One thing though; how do I stop the pop up saying 'The page at b6.caspio.com says' at the top. I just want it to say 'Choose a date after today' Thanks Quote Link to comment Share on other sites More sharing options...
MayMusic Posted October 2, 2013 Report Share Posted October 2, 2013 Did you try to deploy the page and see if that resolves the issue? Quote Link to comment Share on other sites More sharing options...
juancoffee Posted October 3, 2013 Author Report Share Posted October 3, 2013 Hello It is ok if I view it on another computer. I guess it must cache the IP or something... (clearly I've no idea really). Anyway, it works - so that's great. Thanks very much; I really appreciate your help. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted October 10, 2013 Report Share Posted October 10, 2013 You are very welcome 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.