jepoy928 Posted May 7, 2019 Share Posted May 7, 2019 Good day to you guys. I'm working on an attendance system using a QR code / barcode scanner. Using onChage() functionI want to be redirected to a PHP file where it gets the employee number in the URL and validates the employee number and inserts to attendance table. What's wrong with my code? It does not redirect to my desired page. <html lang="en"> <head> <script> function ValidateEmployeeNumber(emp_num) { var emp_num = document.getElementById("emp_num").value; window.location.replace('validate_attendance.php?emp_num='+emp_num); } </script> </head> <body onload="document.AttendanceForm.ecode.focus();"> <form name="AttendanceForm" method="POST"> <h1>Attendance</h1> <div> <input type="text" id="emp_num" name="emp_num" onChange="ValidateEmployeeNumber(this.value)" class="form-control" placeholder="Employee Number"/> </div> </form> </body> </html> I hope you can guide me guys how to make this work. If you have different approach to the problem that works, I am more than willing to study your code. thanks very much Link to comment Share on other sites More sharing options...
requinix Posted May 7, 2019 Share Posted May 7, 2019 Are there any error messages in your browser's developer console? Link to comment Share on other sites More sharing options...
jepoy928 Posted May 7, 2019 Author Share Posted May 7, 2019 Let me check. Thanks for the reply Link to comment Share on other sites More sharing options...
jepoy928 Posted May 7, 2019 Author Share Posted May 7, 2019 There are no error messages. It reads the QR code and barcode but it does not redirect. Should I use other EventListener? Link to comment Share on other sites More sharing options...
requinix Posted May 7, 2019 Share Posted May 7, 2019 I don't see anything in what you posted that deals with QR codes. How about showing us your actual code? Link to comment Share on other sites More sharing options...
jepoy928 Posted May 7, 2019 Author Share Posted May 7, 2019 The cursor is in focus within a textbox onLoad(). The QR code or barcode reader automatically pastes the employee number in the textbox. I want the javascript to redirect to another page with the value pasted in the textbox. If you have a better idea how it should be done, I will study it. Thanks so much. Link to comment Share on other sites More sharing options...
requinix Posted May 7, 2019 Share Posted May 7, 2019 onchange only fires after focus has left. What happens if you click somewhere on the page? Link to comment Share on other sites More sharing options...
Zane Posted May 7, 2019 Share Posted May 7, 2019 String.replace() takes a second argument, the replacement. You're better off just overwriting the location property. window.location = 'validate_attendance.php?emp_num='+emp_num; Also, what is the point of declaring a function that takes an argument and then overwriting that argument immediately? function ValidateEmployeeNumber(emp_num) { //completely destroy the value for emp_num and create it again? var emp_num = document.getElementById("emp_num").value; window.location = 'validate_attendance.php?emp_num='+emp_num; } If this is the approach you're going to use, then either take the parameter out of the function (and the call) or just don't overwrite the variable. Link to comment Share on other sites More sharing options...
requinix Posted May 7, 2019 Share Posted May 7, 2019 3 hours ago, Zane said: String.replace() takes a second argument, the replacement. It's Location.replace, not String.replace. Link to comment Share on other sites More sharing options...
Zane Posted May 8, 2019 Share Posted May 8, 2019 I learn something every day. Link to comment Share on other sites More sharing options...
requinix Posted May 8, 2019 Share Posted May 8, 2019 Looks like a string, acts like a string, isn't a string. Isn't Javascript wonderful? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.