guyfromfl Posted September 24, 2008 Share Posted September 24, 2008 I have a php-based site set up. When the page loads a header.php file is loaded loading variables, classes, css blah blah blah then the page you are going to, puts its content out, then a footer. When I declare an external js file in the header file it doesn't get recognized, but when its in a script tag it gets it (in the calling file). so say you want to goto customers.php, customers.php calls header.php, loads customers.php, then footer.php. If the JS is called externally from header.php, no go, called internally from customers.php we're all good. these functions are used in dozens of instances so I want to put them in one spot. why can't the header file call them? the js is called: <script language="Javascript" type="text/javascript" src="includes/bli.js"></script> in the header.php file. and according to FireBug its loaded, but then I get errors that say its undefined. Thanks Quote Link to comment Share on other sites More sharing options...
web_loone_08 Posted September 24, 2008 Share Posted September 24, 2008 did you look and see what FireBug said was undefined? you may just need to define a variable in your external JS file; that you may have forgot or left out. Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted September 24, 2008 Author Share Posted September 24, 2008 Yea it says the function updateCreditCardName() I am calling is not defined. for testing I commented everything out and added var test = alert("It works"); It is called from an onblur element of a html textbox. Thanks Quote Link to comment Share on other sites More sharing options...
efficacious Posted September 24, 2008 Share Posted September 24, 2008 can you post your JS script section that is calling to your JS file? Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted September 24, 2008 Author Share Posted September 24, 2008 Yea sure its in several different parts: you goto www...../customers.php that includes header.php that has this in the <head> <script src="includes/bli.js" type="text/javascript" language="Javascript"></script> then bli.js is simply function updateCreditCardName() { 5 /* 6 var fNameTxtBox = document.getElementById('fName'); 7 var lNameTxtBox = document.getElementById('lName'); 8 var nameOnCardTxtBox = document.getElementById('ccNameOnCard'); 9 10///////////////////////////////////////////////////////////// 11 var fName = document.frmAddCustomer.fName.value.toUpperCase(); 12alert(fName); 13 var lName = document.addCustomer.lName.value.toUpperCase(); 14 15 document.addCustomer.ccNameOnCard.value = fName + " " + lName; 16 */ 17 18var alt = alert("It works"); 19} remember i commented everything out for now just so it is easier to test if the function is being called. Quote Link to comment Share on other sites More sharing options...
efficacious Posted September 24, 2008 Share Posted September 24, 2008 I don't see, where you are calling the alert? Take the var alt off the alert.. I'm not 100% on it but I'm pretty sure it won't run the alert in its present state. Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted September 24, 2008 Author Share Posted September 24, 2008 in customers.php there is a textbox <input type="text" name="fName" onblur="updateCreditCardName();" /> and the int alt didn't matter, FireBug says its the updateCreditCardName that isn't defined. thanks tho! Quote Link to comment Share on other sites More sharing options...
efficacious Posted September 24, 2008 Share Posted September 24, 2008 ok so if you got her working.. remeber to click on the resolved button. Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted September 24, 2008 Author Share Posted September 24, 2008 no, still no go ??? Quote Link to comment Share on other sites More sharing options...
efficacious Posted September 24, 2008 Share Posted September 24, 2008 try using the FULL path name to the JS file in your import script Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted September 24, 2008 Author Share Posted September 24, 2008 tried that but then FireBug doesn't even read the js file in. usually FireBug knows about it but the HTML doesn't maybe some kind of scope issue? Quote Link to comment Share on other sites More sharing options...
efficacious Posted September 24, 2008 Share Posted September 24, 2008 hmm does it work if you put the import script directly on the page you want? Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted September 24, 2008 Author Share Posted September 24, 2008 only if i put the function there. If I put the script tag with the src it gives the same error??? http://bli.servehttp.com/login.php user testuser pass test then goto customers and then add customer. im trying to get the programming running right now so don't judge the looks btw that account will only be valid for an hour or so Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted September 25, 2008 Author Share Posted September 25, 2008 I had to take the user name down because now there is sensitive data in the database. sorry. Quote Link to comment Share on other sites More sharing options...
web_loone_08 Posted September 25, 2008 Share Posted September 25, 2008 ok - i changed your script slightly - i don't know if the changes i made; was where your error was at or not, but try this out - see if it was what your originally wanted to do and then add the script to an external file and link it to your header.php include page and see if it works. <script type="text/javascript"> function updateCreditCardName() { var fNameTxtBox = document.getElementById('fName'); var lNameTxtBox = document.getElementById('lName'); var nameOnCardTxtBox = document.getElementById('ccNameOnCard'); var fName = document.frmAddCustomer.fName.value.toUpperCase(); var lName = document.addCustomer.lName.value.toUpperCase(); document.addCustomer.ccNameOnCard.value = fName + " " + lName; } </script> <form name="frmAddCustomer"> First Name: <input type="text" name="fName" /> </form> <form name="addCustomer"> Last Name: <input type="text" name="lName" /> <input type="text" name="ccNameOnCard" /> </form> edit: you will have to add the oblur function to the "fName" - for some reason it is not in the code i posted. Quote Link to comment Share on other sites More sharing options...
guyfromfl Posted September 26, 2008 Author Share Posted September 26, 2008 I found the stupid problem, a } got misplaced.... Thats why I LOVE JavaScript.. its so damn picky but wont tell you what the friggin problem is. thanks and sorry for the trouble. Quote Link to comment 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.