AJAX / Jquery Store变量中的下拉值

时间:2015-04-14 16:14:47

标签: php jquery ajax

在我的剧本中,我有以下内容: -



<script>
      $("#country").on("change", function(){
        var selected = $(this).val();
        $("#results").html("<div class='alert-box success'><span><img src='images/shipping_ukrm.jpg'></span> <b>&pound" + selected + " plus Packaging</b></div>");
		$('#frmelement').val(selected);
      })
    </script>
&#13;
&#13;
&#13;

我选择的国家/地区又在下拉选择字段中获取选项值的值,但我想将下拉值(即国家/地区名称)存储在变量中以传递并在表单中使用

任何帮助

这是选择下拉框信息

&#13;
&#13;
echo '<select name="country" id="country" class="span5" />';
	echo '<option value="0" selected>Select Country</option>';
	mysql_connect("$host", "$username", "$password")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");
	$sql1 = "SELECT c.country_id,c.name,pr.price,pr.weight,pr.weight1,pr.class,c.Zone FROM country as c LEFT JOIN postagerates as pr ON pr.class = c.Zone WHERE (pr.weight <= '$totweight' AND pr.weight1 >= '$totweight') ORDER BY c.name ASC";
	$query1 = mysql_query($sql1);
	while ($row2 = mysql_fetch_array($query1)) { 
	echo '<option value = "'.money_format('%.2n', $row2["price"]).'">'.$row2["name"].'</option>';
	}
		echo '</select>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

试试这个:

var selected = $(this).find('option:selected').text()

请参阅Fiddle

答案 1 :(得分:0)

这是代码:

     echo '<select name="country" id="country"  />';
     echo '<option value="0" selected>Select Country</option>';
     echo '<option value = "'.money_format('%.2n', $row2["price"]).'">'.$row2["monday"].'</option>';
 }
 echo '</select>