# calling javascript file in php



## sudhakararaog (Sep 6, 2007)

i have a register.php and confirmregister.php file. in the first file the user fills a registeration form and in the second page they can review what they

entered in the first page and then confirm their registration.

in register.php i am able to call a javascript file which does the validation of the form fields.

however in the confirmegister.php file i am using the same script tag and the same form tag but the javascript file is not being called at all.

please advice how i can call the javascript file in confirmregister.php file.

thanks.


----------



## MMJ (Oct 15, 2006)

Do you have a link or at least some code?


----------



## MaidenFan (Oct 17, 2006)

Firstly, you might be slightly confused about PHP and Javascript - they are two completely separate types of language, so you can't cross-reference the two. What you're referring to is XHTML and JavaScript.

PHP is a *server-side* language that is run on the server, and the resulting output (99% of the time it is XHTML) is sent to the browser - in essence the browser never actually "sees" any PHP because it's all being carried out on the server. JavaScript is a *client-side* language that is run on the user's browser and has no interaction with the server at all.

One thing to check is that both calls to the JS file are being made from the same directory and if they're not, then you should be using directory navigation syntax to point to the directory - so for example:


> ../jscript/script.js


The "double dot slash" will take the script down a directory before moving into "jscript" then finding the file called "script.js".

If you're using Firefox, it has it's own JavaScript debugger, which can be started by going to Tools --> Error Console. This should show you the exact errors that are being produced by your JavaScript.


----------



## sudhakararaog (Sep 6, 2007)

hi

the register.php file is in the root directory, validateform.js file is also in the root directory and confirmregister.php is in a folder called php in the root directory.

i am calling the javascript file in register.php in the following way

in confirm.php i have called the javascript file in the following ways

1.

2.

3.

also i have removed the script tag and copied the entire javascript code into confirm.php file

in both register.php and confirm.php following is the form tag

and this validateform() function is defined in the javascript file

none of the above 3 methods are working, i have tried these 3 options several times but they do not work.

i am able to call the javascript file from confirm.php now, the problem is the javascript code is not being read. i used an alert statement after the validateform() function at the begining and an alert at the end of the validateform() function, only the first alert is being called and the rest of the javascript code is being ignored, even the last alert message is not being called and the confirm.php file is being called.

what i have noticed and might be the problem is, in register.php the form fields are defined as follows

and for the rest in the same manner however in confirm.php the form fields are defined as follows

echo ""; and so on for the others.

since the form elements are now different from how it is defined in register.php i am thinking that this is the reason why the javascript code is being ignored as the way the form elements are defined is NOT which is the convention. so i guess in confirm.php file i need to let the php file know that echo ""; is equivalent to for the javascript code to work in confirm.php file.

please advice if this is the problem or if there is any other solution and how the code should be written.

NOTE= in confirm.php file i want to display to the user what they have entered in register.php so that they can review the information and then click on register button.

if there is no solution i am think of making all the fields as read only in confirm.php and i should advice the users in confirm.php to click on the back button to make changes in register.php

any help will be greatly appreciated.

thanks.


----------



## MMJ (Oct 15, 2006)

Do you have a link or some complete code?


----------



## sudhakararaog (Sep 6, 2007)

could you provide your email address so that i can attach the files and send the files to you. the code is too long for me to copy and paste.

thanks.


----------



## MMJ (Oct 15, 2006)

You can put it at http://pastebin.com. Just post the JavaScript.


----------

