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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.