donagg Posted July 11, 2012 Report Share Posted July 11, 2012 I want to validate a field entry (called 'Big' in the example below) on a submission DataPage to be in a specific numeric range (between 3 and 48 in the example below). I hoped that I could get an error message to appear saying 'value not in the correct range' once the user clicks Submit, similar to the 'required field' message. I have the following code: function validateTextNumericInRange ('InsertRecordBig') { var textInput = document.getElementById('InsertRecordBig'); var value = parseInt(textInput.value, 10); return (!isNaN(value) && value >= 3 && value <= 48); } I am sure I have coding errors - I can't quite work out how Caspio deals with this issue. Please help! Quote Link to comment Share on other sites More sharing options...
ShWolf Posted July 13, 2012 Report Share Posted July 13, 2012 Hi, Insert code into the footer of your DataPage <script type="text/javascript"> function ValidateNumbers() { var n=document.getElementById("InsertRecordBig").value; if(n<3||n>48) { alert("Value not in the correct range. Please enter number between 3 and 48."); return true; } } document.getElementById("Submit").onclick = function() { if (!ValidateNumbers()) { this.submit(); } else { return false; } } </script> By the way, you can do this without JS You can just select Dropdown or Listbox form element for this field and enter custom values. Let me know if this helps. Quote Link to comment Share on other sites More sharing options...
donagg Posted July 13, 2012 Author Report Share Posted July 13, 2012 Many thanks, it works BUT if I try to validate another field on the same DataPage it does not work - ie. I duplicated the code and replaced the field name and message, but I get the second alert message for data entered out of range in the first field. I tried to rename the function as something else but that didn't help. I don't want to use Dropdown option as the range of allowed values can be huge for some of the fields. Can you help with validating for more than one field? Thanks. Quote Link to comment Share on other sites More sharing options...
ShWolf Posted July 27, 2012 Report Share Posted July 27, 2012 Hi, <script type="text/javascript"> function ValidateNumbers() { var n=document.getElementById("YourFirstNumberFieldID").value; if(n<3||n>48) { alert("Value not in the correct range. Please enter number between 3 and 48."); return true; } } function ValidateNumbers2() { var n=document.getElementById("YourSecondNumberFieldID").value; if(n<3||n>48) { alert("Value not in the correct range. Please enter number between 3 and 48."); return true; } } document.getElementById("Submit").onclick = function() { if (!ValidateNumbers()&&!ValidateNumbers2()) { this.submit(); } else { return false; } } </script> And replace YourFirstNumberFieldID and YourSecondNumberFieldID with correct field ids. Also change range for validation of the second field. Let me know if this helps. 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.