2013-10-18 65 views
1

我有嵌入在表格的形式,對初始頁面加載創建:形成價值觀

echo "<form id='showbooking' action='calendar.php' method='post'>"; 
echo "<td name='clickedcalid' value='" . $resarr[$k]['calid']; 
echo "' title='" . $resarr[$k]['coms'] . "' class='hols'>"; 
echo $resarr[$k]['typ'] . "</td></form>"; 

我提交表單點擊表格中的一個單元格時,並想通過被點擊的單元格的值。

<script> 
$(".hols").click(function() { 
    $("#showbooking").submit(); 
}) 
</script> 

重裝後,我與這個測試:

echo "<p> ID of clicked booking was: " . $_POST['clickedcalid']; . "</p>"; 

但價值不被通過,我不知道爲什麼。

可能是因爲表單嵌入在表中?

+2

甲form標籤wrappring一個TD'Oo' – Stphane

+1

應該有命名爲輸入元件'clickedcalid' TDS不會通過數據 –

+1

使用形式元素如<輸入類型=「text」value =「xyz>」使用submit() –

回答

1

您不能將<form>放入tr元素中,包裝td<tr>specification

允許內容:零個或多個<TD>或<個>元件,或它們的混合

另外value屬性不適用於td元件。你需要重構你的標記。

echo '<td class="hols" title="' . $resarr[$k]['coms'] . '">' . 
    '<form id="showbooking" action="calendar.php" method="post">' . 
     '<input type="hidden" name="clickedcalid" value="' . $resarr[$k]['calid'] . '">' . 
     $resarr[$k]['typ'] . 
    '</form>' . 
'</td>'; 
3

首先,form元素需要去td內。其次,只有形式元素的值在表單提交發送,即inputselecttextarea等試試這個:

echo '<td class="hols" title="' . $resarr[$k]['coms'] . '">'; 
echo '<form id="showbooking" action="calendar.php" method="post">'; 
echo '<input type="text" name="clickedcalid" value="' . $resarr[$k]['calid'] . '" />'; 
echo $resarr[$k]['typ'] . '</form></td>'; 
+0

太棒了,這是有效的。我得到的印象似乎很不好,但是你會建議從另一個角度來看嗎? –

+0

你爲什麼使用'text'輸入?在OP的代碼中,它是'td'的'value'屬性,它不應該在頁面上呈現。 – matewka

+0

我確實將輸入類型更改爲隱藏,以使其工作 –

-1

要想從$ _ POST,你需要有輸入標籤

echo "<form id='showbooking' action='calendar.php' method='post'>"; 
echo "<td><input type='text' name='clickedcalid' value='" . $resarr[$k]['calid']; 
echo "' title='" . $resarr[$k]['coms'] . "' class='hols' />"; 
echo $resarr[$k]['typ'] . "</td></form>"; 

謝謝, Naumche

+0

'

'必須是'​​'的孩子。 – matewka