我有一個表格:如何將Jquery的值傳遞給PHP? HTML是一個隱藏的輸入表單字段
<form action="post.php" method="POST">
<p class="select1">Northern Cape</p>
<p class="select1">Eastern Cape</p>
<p class="select2" >New Goods</p>
<p class="select2" >Used Goods</p>
<input id="submt" type="submit" name="submit" value="Submit">
</form>
JQUERY ....追加輸入/值對所選項目:
$(document).ready(function() {
$('.select1').click(function() {
if ($(this).text() == "Northern Cape"){
$(this).append("<input id='firstloc' type='hidden' name='province'
value='Northern Cape' />");
$("#firstloc").val('Northern Cape');
}; // end of if statement
if ($(this).text() == "Eastern Cape"){
$(this).append("<input id='firstloc' type='hidden' name='province'
value='Eastern Cape' />");
$("#firstloc").val('Eastern Cape');
}; // end of if statement
}); // end of click function
}); // end of document ready
$(document).ready(function() {
$('.select2').click(function() {
if ($(this).text() == "New Goods"){
$(this).append("<input id='category' type='hidden' name='cat'
value='New Goods' />");
$(this).val('New Goods');
};
if ($(this).text() == "Used Goods"){
$(this).append("<input id='category' type='hidden' name='cat'
value='Used Goods' />");
$("#category").val('Used Goods');
};
});
});
如何值傳遞給PHP即。第一個值省第二個值類別?
<?php
$province = $_POST['province'];
$category = $_POST['cat'];
echo $province;
echo $category;
?>
我收到一條消息未定義的索引:傳遞給PHP時的cat。 用戶必須選擇2項和值必須傳遞給PHP,我不想使用帶有「選項」的下拉菜單
表單提交它會通過,你沒有得到它? – Exprator
我得到未定義的索引:cat – ticktock
選擇一個值後嘗試查看源代碼以檢查輸入字段是否添加到html頁面 – Exprator