Validate Javascript form by code in a separate file - codesd.com
source link: https://www.codesd.com/item/validate-javascript-form-by-code-in-a-separate-file.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Validate Javascript form by code in a separate file
<script type="text/javascript" src="js/js01.js"></script>
<!-- ... -->
<form id="frmReg" method="post" onsubmit="valRegs()" action="memb_area/register.php">
Why the function valRegs() (code is placed inside js01.js file) is not executed, except I drag the code inside html file ?
How can I be sure that valRegs() is always executed before and not after code inside register.php file ?
By making sure that the script with your validation is below the form in your html.
This is because you are trying to bind to a non-existent element when the script runs.
Alternatively you should wrap your script inside a jQuery $(document).ready()
or by creating an onload function.
Related Articles
How to hide Ruby generated JavaScript code in a separate file?
Save my output code in a separate file?
reactivates the router code in a separate file
JavaScript form validation code loop
Compile JavaScripts with Gulp and resolve dependencies (separate files)
Keep the code in a separate file
Is it possible to put the Template7 code in a separate file rather than in html
PHP checks the empty value from the separate file
How to run PHP from a separate file
How do I call a code-behind method after an external JavaScript validates a form?
Validate the form with PHP and JavaScript?
JavaScript does not validate the form
Validate a form in Javascript does not work
Javascript function to validate the form AND display the loading screen of the css
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK