我有一个下拉选择菜单,我将要使用该菜单返回没有提交按钮且没有页面重新加载的变量的值。 Index.html
<form action="fetch" method="get">
<p>
<select name="POS">
<option>SELECT COURSE</option>
<option value="POS">Agricultural Economics and Extension</option>
<option value="A">Another</option>
</select>
</p>
<p>
<input type="submit" name="check" id="check" value="Submit">
</p>
</form>
PHP页面
if(isset($_GET['check'])){
$POS = 'Agricultural Economics and Extension';
$CC = 'English, Mathematics, Chemistry';
$CO = 'Either Biology or Agricultural Science';
$OS = 'Any one of Physics, Geography and Economics';
}
让该下拉示例的值
<option value="POS">Agricultural Economics and Extension</option>
在PHP中返回定义的值,而无需重新加载页面。
$POS = 'Agricultural Economics and Extension';
答案 0 :(得分:1)
您似乎正在使用jquery,因此只需使用jquery的get函数即可。
<select name="POS" onChange="getUpdate(this)">
<option>SELECT COURSE</option>
<option value="POS">Agricultural Economics and Extension</option>
<option value="A">Another</option>
</select>
<Script language="Javascript">
function getUpdate(selectObject) {
var value = selectObject.value;
$.get( "urlToyourPHPResults.php?POS="+value, function( data ) {
// Do something with returned data
});
}
</script>