在php中获取Option标记值


Get Option tag value in php

我有一个无法解决的问题。部分原因是我无法用正确的术语来解释。我是新手,很抱歉问了这个笨拙的问题。

下面你可以看到我的目标概述。

我正在使用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?>"/>

这里我显示了一个下拉列表,根据我从这个下拉列表中选择的必须填写的剩余字段必须填写。

例如,选择的选项值是25,这是我网站中的产品id,基于该id值,必须在下面填写描述、价格。。。。

为此,我必须在一个变量中获得选项值。。。

使用这个脚本,我得到了选择的选项值

<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>

但我无法将其存储在php中的变量中

有什么想法吗?

您可以通过json将searchbox的值发送到targetfile.php在点击处理程序中

$.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)
      }
});

在targetfile.php中执行print_r($_POST);以查看您得到了什么。看看firebug的控制台选项卡。

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