只不過想到了我的代碼的一部分確實非常簡短的解釋:檢查是否被點擊的按鈕......沒有工作
- 我有兩個按鈕,做不同的事情。
- 其中一人讓通過對任何他/她想要搜索
- 其他表/數據庫中的用戶搜索允許用戶插入東西到數據庫
什麼,我想DO: 我想檢查用戶點擊哪個按鈕,以便執行相應的代碼。
我一直在環顧四周,幾乎無處不在,人們建議使用isset(),但它不適合我。也許我不完全理解isset()是做什麼的,但是它基本上不檢查是否設置了一個變量?
這裏是我的代碼:
<script>
function show(x, y){
<!-- Do something -->
}
</script>
<form>
<button name = "sButton" type = "button" onclick = 'show("searchForm", "insertForm");'>Perform Search</button>
<button name = "iButton" type = "button" onclick = 'show("insertForm", "searchForm");'>Insert Data</button>
</form>
<form id = "searchForm" value "search" style = "display: none;" action = "test2.php" method = "post">
<!-- Do something -->
</form>
<form id = "insertForm" style = "display: none;" action = "test2.php" method = "post">
<!-- Do something -->
</form>
<!-- This is the test2.php page -->
if(isset($_POST['sButton'])){
\t \t \t
<!-- Do something -->
}
else{
\t \t \t
<!-- Do something -->
}
爲了測試它,我有if語句打印 「檢查」 和其他打印「未選中」。當我運行我的代碼時,它會打印「未選中」。我做錯了什麼,我該怎麼做?
在此先感謝!
你現在可以通過在'show'函數中檢查'x'和'y'的值來確定哪個按鈕被點擊了嗎? – sfletche
如果您給這些按鈕一個名稱,那麼被點擊的名稱將與該表單一起提交。或者,偵聽器可以使用'show(「searchForm」,「insertForm」,this.name)''將按鈕的名稱傳遞給函數。爲什麼表單中的按鈕? – RobG
@sfletche嗯,我覺得呢?我的按鈕按我希望的方式工作,所以我認爲它很好。 – wuv1