fusweb Posted June 23, 2012 Report Share Posted June 23, 2012 Hi, I've created a script that takes a 'MMYY' date in a string (Version_Date) and creates a new field in 'YYMM' format (Logical_Date). The input has to be a string not a number (to capture leading zeros such as 0612). I need to add some validation to check if the 'Version_Date' field (MMYY) is numeric, if not - alert the user and then return to the submission form. If the string is numeric then the JS continues and switches MMYY to YYMM etc. The JS is as follows function concatenate() { var Version_Date = document.getElementById("InsertRecordVersion_Date").value; '''''''''''''''''''''''''''''''''''''' I'm guessing the validation needs to go here somehow :/ var URN = document.getElementById("InsertRecordURN").value; document.getElementById("InsertRecordConcat_URN").value = URN + "_" + Version_Date; var MM = Version_Date.substr(0,2) var YY = Version_Date.substr(2,2) document.getElementById("InsertRecordLogical_Date").value = YY + MM; } document.getElementById("caspioform").onsubmit=concatenate; Any assistance / comments very welcome. Thanks Mat Quote Link to comment Share on other sites More sharing options...
fusweb Posted June 23, 2012 Author Report Share Posted June 23, 2012 I've managed to get this working but my JS is not skilled at all. This works but is probably not coded very well. function Validate() { var Version_Date = document.getElementById("InsertRecordVersion_Date").value; var ValidChars = "0123456789"; var IsNumber=true; var Char; for (i = 0; i < Version_Date.length && IsNumber == true; i++) { Char = Version_Date.charAt(i); if (ValidChars.indexOf(Char) == -1) { alert("Non-Numeric Version Date"); IsNumber = false; } else { var Version_Date = document.getElementById("InsertRecordVersion_Date").value; var URN = document.getElementById("InsertRecordURN").value; document.getElementById("InsertRecordConcat_URN").value = URN + "_" + Version_Date; var MM = Version_Date.substr(0,2) var YY = Version_Date.substr(2,2) document.getElementById("InsertRecordLogical_Date").value = YY + MM; } } return IsNumber; } document.getElementById("caspioform").onsubmit=Validate; 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.