简体   繁体   中英

Get Option tag value in php

I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.

Below you can see an overview of my goal.

I'm using Magento CE 1.7.0.2

<div id="display">
    <?php 
        if (sizeof($final_na)>0) { 
            $i = 0;
        ?>
        <select size="5" class="auto-search" style="height:132px;width: 420px;padding:0px;" name="hero">
            <?php foreach ($final_na as $key => $value) { ?>
                <option style="text-align:center;padding: 5px 0 0;" value="<?php echo $final_na1[$i]; ?>" class="display_box" align="left" onclick="fill('<?php echo $value;?>')">
                    <?php echo $value; ?>
                </option>
                <?php $i++; ?>
            <?php } ?>
        </select>
    <?php } ?>
</div>
    <label for="description" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Description') ?> :</label>
    <textarea name="description" class="required-entry " id="description" rows="5" cols="75" ><?php echo $description?></textarea>

    <label for="price" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Price') ?> :</label>
    <input type="price" class=" required-entry widthinput" name="price" id="price" value="<?php echo $price?>"/>

here i'm displaying a dropdown,based on my selection from this dropdown have to fill the remaining fields have to fill.

for example selected option value is 25 this is product id in my site based on that id values have to fill below like description,price....

for this i have to get that option value in one variable...

Using this script i'm getting the selected option value

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
            $('#display').click(function(){ 
                var searchbox = $("#display :selected").val();
                alert(searchbox);
            });
        });
</script>

but i can't store it in a variable in php

Any ideas ?

you can send the value of searchbox via json to targetfile.php inside your click handler

$.ajax({
      url: "targetfile.php",
      type: "POST",
      dataType : "json",
      data: {"hero":searchbox},
      success: function(data) { 
         // something that should happen after success
         // data is filled with the output of targetfile.php (should be json)
      }
});

do print_r($_POST); in targetfile.php to see what you get. And take a look at the Console tab of firebug.

http://api.jquery.com/jQuery.ajax/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM