![](/img/trans.png)
[英]Not able to fetch selected value from dropdown into a php variable, and use the value of that variable to fetch other data
[英]use selected dropdown box value as variable in php
我想在下拉框中使用选定的值作为我的functions.php文件中的PHP变量。 我尝试使用jquery-ajax
$(document).ready(function(){ $("#pa_color").change(function(){ var result= $(this).val(); document.getElementById("demo").innerHTML = result; if (result.length == 0) { document.getElementById("tit").innerHTML = ""; return; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("tit").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "selectcolor.php?q=" + color, true); xmlhttp.send(); }); });
并且可以使用getElementById(“demo”)获取要在网站上显示的变量,但在尝试使用我的selectcolor.php文件调用和处理变量时会收到404消息。 我宁愿只使用PHP,但会使用任何必要的东西。 我可以使用PHP获得与每个项目相关的所有颜色
$color = $product->get_attribute('pa_color');
但我只想要选择的颜色。 正如你所看到的,我是新手,我的知识有限。 谢谢
$('#pa_color').val()
将输出下拉元素的选定值。
使用此选项可获取所选选项文本。
$('#pa_color option:selected').text();
现在你可以使用这个值使用AJAX或其他东西传递给你的php文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.