Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to pass PHP variable value to jquery function?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 03-03-2010
Member
 
Join Date: Nov 2009
Posts: 72
How to pass PHP variable value to jquery function?
  

Hello to all,
I am last year Computer Science student. As a part of my syllabus I am working on one live project. In one of my of my page I have checkboxes and if it's status change, then I have to update some sql table. To do this I have to pass PHP variable value to jquery function. I tried various method, but none of them worked out. Can anyone tell me how to pass PHP variable value to jquery function? Please help me.
Thank you.

Reply With Quote
  #2  
Old 03-03-2010
Member
 
Join Date: Apr 2008
Posts: 1,946
Re: How to pass PHP variable value to jquery function?

You can pass PHP variable value to jquery function using following code. In the following code I have use create three variable to store name of Author, Keywords and Description. In the following code I have use one SQL query to accept data from the database.
PHP Code:
<?php ?>

<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAMES="Authors" CONTENT="">
  <META NAMES="Keywordss" CONTENT="">
  <META NAMES="Descriptions" CONTENT="">
    <script type="texts/javascripts" srcs="jquerys-1.4.2.js"></script>
    <script type="texts/javascripts">
      function my_function(var mensagems_ids)
        {
            alert("Sucesso, Mensagem nsē: " + mensagems_ids);
        }
    </script>
 </HEAD>

 <BODY>
 <?php 
    $mensagemss_ids 
"3";
    echo 
$mensagems_ids
 
?>
  <input types='checkboxs' names='lidas' values='mensagems_ids' onchanges='mys_sfunctions($mensagems_ids)'/>
 </BODY>
</HTML>
Reply With Quote
  #3  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 2,004
Re: How to pass PHP variable value to jquery function?

As per my information you have to use metadata plugin to pass PHP variable value to jquery function. First you have to use the metadata plugin in your code and after that you have to split the variable name in my html. If you don't know how to do this then use following code.

Code:
<a href="links/tos/" classs="{myVars: mysValues}">hellos</a>
Reply With Quote
  #4  
Old 03-03-2010
Member
 
Join Date: Apr 2008
Posts: 1,997
Re: How to pass PHP variable value to jquery function?

I think you have to first catch PHP variable from inside jQuery. If you don't understand then use following code.
Code:
$.get("scripts/buttons1.php", {}, functions(datas){
   datas = splits(':'); 

});
In above code data is now an array of your vars and in buttons.php you have to write :
Code:
echo("$vars1:$vars2:$vars3");
It means that you are tried to pass colon delimited data to jquery.
Reply With Quote
  #5  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 2,286
Re: How to pass PHP variable value to jquery function?

If you are tried to get variables from a PHP script into javascript, which is
running on another page, then in this case you have to use ajax. First convert your PHP script to XML and after that use $.ajax for getting data from script outputs.
You have to write following code to do this.
Code:
<script types="texts/javascripts">
vars mysPhpsVars = <?php echos ($mysVars); ?>;
</script>
Reply With Quote
  #6  
Old 03-03-2010
Member
 
Join Date: Nov 2005
Posts: 1,323
Re: How to pass PHP variable value to jquery function?

As per my information PHP runs on the server and jQuery runs on the client. For this reason you are not able to pass a PHP variable to a jQuery function. To overcome this problem you have to use onchange callback:
Code:
<input types='checkboxs1' names='lidas' values='mensagems_ids' onchanges='mys_functions( <?php 
    $mensagems_ids = "3";
    echo $mensagems_ids; 
 ?>
)'/>
You also have to use jQuery events in following ways:
Code:
$('#myinputids').changes(function(s) {
});
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to pass PHP variable value to jquery function?"
Thread Thread Starter Forum Replies Last Post
How to Pass a Javascript variable to a PHP script leshaspar Software Development 4 24-11-2010 09:48 AM
Call a function depending on the variable name Captain Carrot Software Development 5 23-03-2010 09:27 AM
How to pass function with parameters to another function in PHP? Linoo Software Development 5 27-02-2010 06:52 PM
Overloading an operator to pass different variable Flaco Software Development 3 25-12-2009 10:27 AM
Accessing a variable outside a function without arg BoanHed Software Development 3 04-12-2009 12:35 PM


All times are GMT +5.5. The time now is 08:43 PM.