how to pass java script variable in php

Discussion in 'PHP' started by dineshsingh1984, Jan 18, 2011.

  1. #1
    how to pass java script variable in php or how to call java script variable in php code

    plz help me............
     
    dineshsingh1984, Jan 18, 2011 IP
  2. cerahil

    cerahil Well-Known Member

    Messages:
    72
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    113
    #2
    you can not pass client side scripting data to server side scriptig

    javascript is client side scripting

    php is server side scripting


    you can pass data from PHP to javascript but never from Javascript to PHP
     
    cerahil, Jan 18, 2011 IP
  3. Zetiz

    Zetiz Active Member

    Messages:
    668
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #3
    You are trying to mix up client side language into server side programming. Like Cerahil said, you can do the reverse however.
     
    Zetiz, Jan 18, 2011 IP
  4. swashata

    swashata Member

    Messages:
    86
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #4
    Actually you can use AJAX technique to pass the value of a variable through URL parameters [GET method]. For example, if we use say, jQuery framework and would like to change the content of a div element having id = result, then the following technique would work:
    $('#result').load('my_ajax.php?my_var='+js_var_name);

    of course, the my_ajax.php file needs to handle the $_GET['my_var'] to generate the result.
     
    swashata, Jan 18, 2011 IP
  5. langtusitinh225

    langtusitinh225 Greenhorn

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    Using ajax to solve this problem
     
    langtusitinh225, Jan 18, 2011 IP
  6. atxsurf

    atxsurf Peon

    Messages:
    2,394
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    0
    #6
    not sure what your tyring to achieve, but if You have POST it, you could read it in php
     
    atxsurf, Jan 18, 2011 IP
  7. buddyborg

    buddyborg Guest

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    to use javascript in PHP you have to use a seperate serverside script to accept the javascript clientside data. many people acheve this through IFRAMES. in the IFRAME, have it accept POST or GET data via PHP. then as it has processed the data, it can then use javascript to manipulate the original user window via javascript : window.top - DOM element.
     
    buddyborg, Jan 19, 2011 IP
  8. bozy12v

    bozy12v Active Member

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #8
    bozy12v, Jan 19, 2011 IP