我正在爲一家餐廳構建網站,並使用php和mysql動態地在表單中構建表格以顯示每個菜單項。每一行都有一個數量輸入,其後是項目和說明等,並以「添加到訂單」按鈕結束。我需要做的是按下按鈕時,將項目的數量和ID發送到會話變量。我已經看到使用數組作爲輸入ID的建議不知道如何處理它們,我猜。如何從動態構建的表格中捕獲表格
$d=date('N');
$sql2="CALL SP_GET_MENU_ITEM('entree', '$d');";
$result=mysql_query($sql2, $conn2);
if(!$result)
die(mysql_error());
$count=0;
while($row=mysql_fetch_assoc($result)){
$n=$row['itemName'];
$de=$row['description'];
$i=$row['ingredient'];
$p=$row['price'];
$dr=$row['dietRestrict'];
$f=$row['path'];
/*$pic="CALL SP_GET_MENU_IMAGE('$n');";
$picTry=mysql_query($pic, $conn);
$picResult=mysql_fetch_assoc($picTry);
$f=$picTry['path'];*/
print '<tr><td>
<input type="number" min="1" name="quantity" style="width:40px;" /></td>
<td class="itemDes">';
print "<h2>".$n."</h2>";
print "<img src='../admin/menu/".$f."' alt='foodPic'></td>";
print "</td><td><p>description: ".$de."<br>ingredients: ".$i."</td><td>".$dr."</td><td>".$p."</td></p></td><td>
<input type='button' onclick= 'doit()' value='Add to Order' class='btn'/>
}
它填充表正確地,現在,和功能度特()[其只是調用警報]任一按鈕被按壓時正確調用。我想我必須通過變量,即<onclick="doit(quantity.value))">
那麼我怎麼會得到quantity.value
工作?
嘗試:'的onclick = 「返回DOIT(的document.getElementById(」' –
威爾返回,只是該行的值項目Id 「)值()。)」?現在每個數量輸入都會有相同的ID,我認爲會影響它? – sgriffin
請嘗試:onclick =「doit($(」input [name ='quantity']「).val())」這應該是有效的,請問我是否知道它是否有效 –