variable value from javascript to php

Discussion in 'JavaScript' started by coldfire7, Mar 29, 2009.

  1. #1
    I need to get value from Javascript to Php, the scenario is below:

    I have a drop-down list which is loaded through ajax call, i couldnot find any means to get the value of selected index value of list to a php variable.

    help plz

    thanks
     
    coldfire7, Mar 29, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    it's probably not the conventional way but I just use an image tag and load the source, assuming you only need to set a variable and not give a response.
    
    <script type="text/javascript">
        function selchange() {
        document.getElementById("img1").src = "Default.aspx?LID=" + document.getElementById("select1").selectedIndex;
        }
    </script>
    <img style="display:none" id="img1" />
    <select id="Select1" name="D1" onchange="selchange()">
            <option>Option 1</option>
            <option>Option 2</option>
            <option>Option 3</option>
    </select>
    
    Code (markup):
    I don't use php but you would then have setvar.php which would save the value from the querystring("LID") into a session variable.
     
    camjohnson95, Mar 29, 2009 IP
  3. coldfire7

    coldfire7 Peon

    Messages:
    504
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have used the hidden input text field as a way to assign the value. It does assign it. BUT, this all (Dropdown list and hidden text field is in iframe and I do not post it) is inside the iframe. I want to get the hiddentext field value on the parent page,

    e.g.
    <?php
    $value = $_POST['hiddentextfield'];
    ?>
     
    coldfire7, Mar 30, 2009 IP