tags:

views:

58

answers:

2
<input id="Edit" name="Edit" value="Edit Record" type="button" onclick="$.get('fetchvalues.php', function(){myCallBack(ReadCookie('UpdateRecordID'));});" />

The ReadCookie function is of another JQuery script.

I want to pass the cookie value to the .php file.

+4  A: 

Can't say from what you have just written.

I Would be interested to see more on: myCallBack, fetchvalues.php and ReadCookie

Certainly, start by making the JavaScript unobtrusive, and moving the click binding to the document ready function.

$(document).ready(function(){
    $("#edit").click(function(){
        $.get('fetchvalues.php', function(){
            myCallBack(ReadCookie('UpdateRecordID'));
        });
    });
});

Another problem. If you're wanting to pass data, then data is the second parameter on the get function. See the documentation here:

http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktype

So, your function might be something like:

        $.get('fetchvalues.php', ReadCookie('UpdateRecordID'), myCallBack);

(p.s. check out the following for the click binding: http://docs.jquery.com/Events/click)

James Wiseman
How to execute the above code? I want it to be execute on the click of a button.
RPK
Suggest you read up on late binding. This line above helps you. $("#edit").click(function(){
James Wiseman
What is the first parameter?
RPK
Check out the get link on the post. jQuery.get( url, [data], [callback], [type] )
James Wiseman
A: 

This how I modified:

<td align="left">
    <input id="Edit" name="Edit" value="Edit Record" type="button" onclick="$.get('fetchvalues.php', ReadCookie('UpdateRecordID'), myCallBack);" />
</td>

<script type="text/javascript">
       $(document).ready(function(){
       $("#edit").click(function(){
       $.get('fetchvalues.php', function(){
       myCallBack(ReadCookie('UpdateRecordID'));
       });
   });
});
</script>

In the file: fetchvalues.php, I have written an echo statement to check whether AJAX call reaches there or not. But it is not calling that file. What's wrong?

RPK