[英]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.