I apologize for the noob question, I just do not know yet JS (I am learning java).
I have a form:
<form onsubmit="return checkForm(this)"action="/search" method="POST"> <div id="fields_container"> <div> <div class="element">First name:</div> <input id="name" type="text" name="" placeholder="James" /> <span id="err_name" class="error"></span> </div> <div> <div class="element">Email:</div> <input id="email" type="text" name="" placeholder="example@email.com" /> <span id="err_email" class="error"></span> </div> </div><!-- #fields_container> --> <div> <input type="submit" value="Submit"> </div> </form> and there is a script that I specify in the head
< script type = "text/javascript" > function checkForm(form) { valid = true; if (document.getElementById('name').value.replace(/^\s*/, '').replace(/\s*$/, '') == "") { document.getElementById('err_name').innerHTML = 'Enter your first name'; valid = false; } else { document.getElementById('err_name').innerHTML = ''; }; pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([az]{2,6}(?:\.[az]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); emailAddress = document.getElementById('email').value; if (emailAddress == "") { document.getElementById('err_email').innerHTML = 'Enter your email'; valid = false; } else if (!pattern.test(emailAddress)) { document.getElementById('err_email').innerHTML = 'Wrong email, please correct this field'; } else { document.getElementById('err_email').innerHTML = ''; }; return valid; }; < /script> those. when you click on the "submit" button, the correctness of the form is checked. How can I put this script into a separate file and how to correctly register it for execution on the html page?