javascript - how do you get onfocus to read from an external js file -
javascript - how do you get onfocus to read from an external js file -
so want access function in .js file html using "onfocus" attribute, doesn't work. hate having write js within html makes cluttered , harder read/debug later on.
so here html code "jmlessons.html":
*<input type="text" required="required" id="pfirstname" name="pfirstname1" placeholder="required" maxlength=35 minlength=1 onfocusout="pfn1()"></input> so function i'm trying phone call "pfn1()" in "jmlessons/jmlessons.js"
i have code in html head section:
<script type="text/javascript" src="jmlessons/jmlessons.js"></script> when re-create , paste function html in between proper "" opening , closing tag , run in browser works, delete browser , seek pull js file, breaks it. went far re-create , paste function js since thought might have written wrong. there way utilize onfocus in ".html" , access function in separate ".js" file?
here's js function reference:
function pfn1() { var p1n1 = document.getelementbyid("pfirstname"); if (p1n1.value.length === 0 || p1n1.value === " ") { document.getelementbyid("pfirstname").classname="wrongreq"; homecoming false; } if (/\d/.test(p1n1.value)) { document.getelementbyid("pfirstname").classname="warningreq"; homecoming false; } else { document.getelementbyid("pfirstname").classname="goodreq"; homecoming true; } } it changes border color of text field based on special conditions allow user know if he/she entered correctly.
it depends on when load js file.
try set code <script type="text/javascript" src="jmlessons/jmlessons.js"></script> in <head> tag. if doesn't work, set same code in bottom of html page.
javascript html
Comments
Post a Comment