dadamssg Posted April 17, 2009 Share Posted April 17, 2009 i have a login section that i want to put in my header on every page. It has javascript which i put in the head section of the html. can i save all the javascript in an include file and make it a function and echo it in the head section? would that work? if so...should i save the file as .php or .inc or does it matter? Quote Link to comment https://forums.phpfreaks.com/topic/154529-solved-include-javascript/ Share on other sites More sharing options...
ober Posted April 17, 2009 Share Posted April 17, 2009 Save the JavaScript in a .js file and echo something like this: <script type="text/javascript" src="whatever.js"></script> Quote Link to comment https://forums.phpfreaks.com/topic/154529-solved-include-javascript/#findComment-812488 Share on other sites More sharing options...
dadamssg Posted April 17, 2009 Author Share Posted April 17, 2009 oh ok...so just save it in a .js file in the same directory as the html and php files..sweet thanks Quote Link to comment https://forums.phpfreaks.com/topic/154529-solved-include-javascript/#findComment-812500 Share on other sites More sharing options...
dadamssg Posted April 17, 2009 Author Share Posted April 17, 2009 so i would save this EXACT file as whatever.js? ive never save a .js file and don't know if i need to include anything at the top or bottom to open/close the javascript...im assuming that this is correct though <script language="javascript"> function changeBox() { document.getElementById('pass').style.display='none'; document.getElementById('pass2').style.display=''; document.getElementById('fpassword').focus(); } function restoreBox() { if(document.getElementById('fpassword').value=='') { document.getElementById('pass').style.display=''; document.getElementById('pass2').style.display='none'; } } function changeBox1() { document.getElementById('user').style.display='none'; document.getElementById('user2').style.display=''; document.getElementById('fusername').focus(); } function restoreBox1() { if(document.getElementById('fusername').value=='') { document.getElementById('user').style.display=''; document.getElementById('user2').style.display='none'; } } </script> Quote Link to comment https://forums.phpfreaks.com/topic/154529-solved-include-javascript/#findComment-812505 Share on other sites More sharing options...
ober Posted April 17, 2009 Share Posted April 17, 2009 Remove the <script> tags, otherwise, yes. Quote Link to comment https://forums.phpfreaks.com/topic/154529-solved-include-javascript/#findComment-812507 Share on other sites More sharing options...
dadamssg Posted April 17, 2009 Author Share Posted April 17, 2009 alright...so no <script language="javascript"> or </script> i guess saving it as a .js file would make that unnecessary Quote Link to comment https://forums.phpfreaks.com/topic/154529-solved-include-javascript/#findComment-812514 Share on other sites More sharing options...
ober Posted April 17, 2009 Share Posted April 17, 2009 Right. Quote Link to comment https://forums.phpfreaks.com/topic/154529-solved-include-javascript/#findComment-812539 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.