2
我有一個頁面,我正在動態生成文本框和下拉列表。我試圖從下拉列表中選擇一個名稱,然後在其旁邊的文本框中顯示它。問題是我能夠做到這一點只爲第一行,我的意思是我可以從第一個下拉列表中選擇一個名稱,然後在它旁邊的文本框中顯示它。但我無法爲其他人做到這一點。你能幫忙嗎?無法從文本框中的下拉列表中獲取名稱
這裏是我的代碼
請注意:我使用JavaScript來顯示什麼用戶從下拉列表中選擇,並顯示在 文本
<?php
if(isset($_POST['team'])){
$selectedTeam = $_POST['team'];
$selectedWeek = $_POST['week'];
//getting team member names from resolver table
$query = "SELECT * FROM `names` WHERE `teamName` = '$selectedTeam'";
$query_run_teamName = mysql_query($query);
while($query_row = mysql_fetch_assoc($query_run_teamName)){
$verNAME[] = $query_row['verNAME'];
}//end of while
}//end of if condition
?>
<!DOCTYPE html>
<html>
<head>
<title>Option Page</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="roster.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript">
//Function below gets ID and assigns value to the left text field
function getValue(RightTextfield, leftTextfield){
var TextfieldValue = _(RightTextfield).value;
_(leftTextfield).value = TextfieldValue;
}//end of getValue() function
function _(x){
return document.getElementById(x);
}//end of _(x) function
</script>
</head>
<body>
<div id="wrapper">
<form action="teamRoster.php" enctype="multipart/form-data" method="POST">
<div id="response"></div><!--End of response Div-->
<?php
for ($i = 0; $i <= $count; $i++) {
echo '<div class="STeam">';
//code below to generate Text Fields dynamically
echo '<input type="text" id="r1Value1" name="r1Value1">';
//code below to generate dropdown list dynamically
echo '<select id="ChooseMember" name="ChooseMember" onchange="getValue(\'ChooseMember\', \'r1Value1\')">';
echo '<option value="">Select Team Member</option>';
foreach ($verNAME as $key) {
echo '<option value="'[email protected]$key.'">'[email protected]$key.'</option>';
}
echo '</select>';
echo '</div>';
}//End of for loop
?>
<!--Passing week and team name as hidden values-->
<input type="hidden" id="HiddenDay" name="HiddenDay" value="<?php echo $selectedWeek;?>">
<input type="hidden" id="HiddenTeam" name="HiddenTeam" value="<?php echo $selectedTeam;?>">
</form>
</body>
</html>
謝謝
你有'name =「HiddenTeam」value =「<?php echo $ selectedTeam'然而你正在使用'$ selectedTeam = $ _POST ['team']'你的POST不匹配,檢查其他。 – 2014-11-04 00:49:38