How should I call jquery from my php page?

This is my php page:

<form action="#" method="post">
    <input type="file" name="fileInput" id="fileInput" />
    <input type="submit" value="submit" disabled />
</form>
<div id="result"></div>

And this is the js file:

$(document).ready(
    function(){
        $('input:file').change(
            function(){
                if ($(this).val()) {
                    $('input:submit').attr('disabled',false);
                }
            }
            );
    });

Thanks!

If both your js file and jquery are linked in your page, then this code will execute automatically when the page is done loading.

use

<script></script>

and put your code in between them on PHP Page.

How should I call jquery from my php page?

This is my php page:

<form action="#" method="post">
    <input type="file" name="fileInput" id="fileInput" />
    <input type="submit" value="submit" disabled />
</form>
<div id="result"></div>

And this is the js file:

$(document).ready(
    function(){
        $('input:file').change(
            function(){
                if ($(this).val()) {
                    $('input:submit').attr('disabled',false);
                }
            }
            );
    });

Thanks!

Suppose you have your JavaScript code in a file 'yourFile.js'. Your PHP and JavaScript file should be in the same directory. In php file, just add

<script type="text/javascript" src="yourFile.js"></script>

This line of code should be placed before the <head> tag. If your page dpnt have any <head> tag and only PHP code, then just add the line at the begining of the PHP file

When I put the js file link on the head; the link is as follow:

<script src="jquery.js" type="text/javascript"></script>

I got the error as follows:
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; AskTB5.6)
Timestamp: Wed, 16 Feb 2011 00:38:36 UTC


Message: Object expected
Line: 2
Char: 1
Code: 0
URI: http://localhost/picturetopic/jquery.js

Please downlaod latest Jquery File from the official website and use it, its very simple issue.

Thanks guys! I solved it.
Yes, after i download the latest js file, it worked!
Thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.