Results 1 to 6 of 6

Thread: How to pass PHP variable value to jquery function?

  1. #1
    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.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    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>

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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>

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    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>

  6. #6
    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) {
    });

Similar Threads

  1. How to Pass a Javascript variable to a PHP script
    By leshaspar in forum Software Development
    Replies: 4
    Last Post: 24-11-2010, 10:48 AM
  2. Call a function depending on the variable name
    By Captain Carrot in forum Software Development
    Replies: 5
    Last Post: 23-03-2010, 09:27 AM
  3. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  4. Overloading an operator to pass different variable
    By Flaco in forum Software Development
    Replies: 3
    Last Post: 25-12-2009, 11:27 AM
  5. Accessing a variable outside a function without arg
    By BoanHed in forum Software Development
    Replies: 3
    Last Post: 04-12-2009, 01:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,403,998.21146 seconds with 17 queries