UltraSrc Posted January 24, 2017 Report Share Posted January 24, 2017 When one of my end users fills out a form then need to use the barcode scanner. An example of the text would be "%247463$1$0$4$20%". My script below is suppose to extract everything after the first two characters up to the last character. It works but it is also showing the original along with it. <script> function modify() { //Store the value in the field to trim. var trim = document.getElementsByName("InsertRecordBarcode")[0].value; //Take a substring of trim and store it back into new trim value. trim = trim.match("%2(.*)%"); //Set the value of the weight field in the form to the new substring document.getElementsByName("InsertRecordBarcode")[0].value = trim; //the new value in the field is what is submitted. } //When the form is submitted called method modify. document.getElementById("caspioform").onsubmit=modify; </script> My result showing is "%247463$1$0$4$20%,47463$1$0$4$20". What am I doing wrong as I want it to only show the 47463$1$0$4$20. thank you. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted January 27, 2017 Report Share Posted January 27, 2017 try to remove the value of the text field before assigning new value function modify() { //Store the value in the field to trim. var trim = document.getElementsByName("InsertRecordBarcode")[0].value; //Take a substring of trim and store it back into new trim value. trim = trim.match("%2(.*)%"); //Set the value of the weight field in the form to the new substring document.getElementsByName("InsertRecordBarcode")[0].value = ""; document.getElementsByName("InsertRecordBarcode")[0].value = trim; //the new value in the field is what is submitted. } 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.