Jump to content

[SOLVED] JavaScript and php include problem


guyfromfl

Recommended Posts

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

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

 

 

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.

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!

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.