@alditis TY,試過了你的建議,但是javascript在它之後不工作。這不需要那麼安全,因爲沒有涉及任何敏感數據,而且隨着我的進行,我有點了解它。此外,我將沿軌道使用這些查詢,所以我寧願將整個數組放在那裏。
@Barmar是的,第二個snippit顯示Google Chrome如何使用調試器查看輸出。這就是爲什麼它很奇怪。
@FreudianSlip我正在嘗試一些東西,永遠不會放回來。
@saeed arab sheybani我不太明白?代碼工作和列表填充就好了問題是$ _REQUEST ['pos_no']似乎不存在。它應該按照輸出代碼進行提交。也許我不明白你在說什麼,你是否有一個可以鏈接到我的例子?
我試圖讓一個PHP/JavaScript的動態填充組合框,通過MySQL的查詢工作,在大多數情況下它工作得很好,這是直到我打提交按鈕。這些腳本完全符合我想要的。
從我可以看到替換代碼被省略$ _POST數組。我認爲這是因爲一旦表單加載,它列出了期望的字段或創建$ _post數組,因此通過插入一些新的代碼它可能會忽略它?只是一個猜測,但似乎是合乎邏輯的,如果是這樣,一個人將如何解決這個問題?這一直困擾着我一個月左右。
的javascript:
<script type="text/javascript">
$(document).ready(subpos_selectbox_change);
function subpos_selectbox_change(){
$('#subpos').change(update_position_number);
}
function update_position_number(){
var subpos=$('#subpos').attr('value');
$.get('get_list.php?subpos='+subpos, show_posnumbers);
}
function show_posnumbers(ss){
$('#position_number').html(ss);
}
</script>
get_list.php
switch($_REQUEST['subpos']){
case 'AO2';
$teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO2'";
break;
case 'AO3';
$teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO3'";
break;
case 'AO4';
$teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO4'";
break;
case 'AO5';
$teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO5'";
break;
case 'AO6';
$teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO6'";
break;
case 'AO7';
$teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO7'";
break;
case 'AO8';
$teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='AO8'";
break;
case 'SO1';
$teamQuery = "SELECT * FROM establishment_positions WHERE position_filled='0' AND active='1' AND position_acrynom='SO1'";
break;
}
echo '<select name="pos_number" id="pos_number">';
$ss = null;
$result = mysql_query($teamQuery);
while($row = mysql_fetch_array($result))
{
$ss.= '<option value=' . $row['position_id'] . '>' . $row['position_number'] . '</option>';
}
echo $ss;
echo '</select>';
..和這裏的id之前的JavaScript的HTML代碼上班:我改變後
<div class="newusr">
<table>
<form id="newusr" action="includes/insertuser.php" method="post">
<tr><td>First Name: </td><td><input type="text" name="firstname"></td></tr>
<tr><td>Middle Name: </td><td><input type="text" name="middlename"></td></tr>
<tr><td>Last Name: </td><td><input type="text" name="lastname"></td></tr>
<tr><td>Username: </td><td><input type="text" name="usr"></td></tr>
<tr><td>sex:</td><td><select name="sex"><option value="1">Male</option><option value="0">Female</option></select></td></tr>
<tr><td>Position: </td><td><select name="subpos" id="subpos"><?php echo $subpos; ?></select><td></tr>
<tr><td>Position No: </td><td id="position_number"><select name="pos_number"><option value="">choose a Position first</option></select></td></tr>
<tr><td>Contractor: </td><td><input type="checkbox" name="contractor" value="1"></td></tr>
<tr><td>Start date: </td><td><input type="date" name="empStrtDte"></td></tr>
<tr><td>Active: </td><td><input type="checkbox" name="active" value="1"></td></tr>
<tr><td><?php echo '<input type="submit"><input type="reset" value="Reset"></td></tr>'; ?>
</form>
</table>
</div>
HTML代碼subpos中的值(來自Chrome):
<select name="subpos" id="subpos">
<option value="AO2">AO2</option>
<option value="AO3">AO3</option>
<option value="AO4">AO4</option>
...
</select></td>
<select name="pos_number" id="pos_number">
<option value="2">805620121</option>
<option value="10">805678998</option>
</select>
一切看起來不錯,這正是我想要的。然後我打印陣列和繁榮,缺少pos_number值,我不知道爲什麼。
Array
(
[firstname] => test
[middlename] => test
[lastname] => test
[usr] =>
[sex] => 1
[subpos] => AO3
[empStrtDte] => 2012-02-19
)
我認爲沒有必要對get_list.php切換。您可以更改爲:$ teamQuery =「SELECT * FROM WHERE establishment_positions position_filled ='0'AND active ='1'AND position_acrynom ='」。 $ _REQUEST ['Subpos']。 「'」;另外你應該避免sql注入。 – alditis
從'get_list.php'返回的HTML包含'
爲什麼這樣做: