[英]Need drop-downs option value in form action query-string
我正在使用PHP + HTML
我有一個動作定義如下的表格:
1]表單action =“ index.php?option = com_advertisment&task = keysearch&Itemid = 2&catid = this.options [this.selectedIndex] .value”
但是當我提交表單時,下拉列表的選定值未顯示在查詢字符串中。
這意味着this.options[this.selectedIndex].value
不會被value
取代,而是像這樣在查詢字符串中出現:
http://mydemoserver.com/index.php?option=com_advertisment&task=keysearch&Itemid=2&catid=this.options[this.selectedIndex].value
如果有人知道解決方案,請幫助我。
謝謝
您似乎正在嘗試錯誤地混合HTML和JS。
如果您有<form>
標記,只需將所有字段放在標記內。
如果希望前三個查詢參數對是靜態的,則可以將它們寫在隱藏的<input>
標記內。
例如:
<form action = "index.php" method = "GET">
<input type = "hidden" name = "option" value = "com_advertisment" />
<input type = "hidden" name = "task" value = "keysearch" />
<input type = "hidden" name = "Itemid" value = "2" />
<select name = "catid">
<option value = "1">Some option</option>
<option value = "2">Another option</option>
</select>
<input type = "submit" />
</form>
確保已為下拉列表/選擇框指定了name
屬性。
eg. <select name="foobar"><option value='first'>First</option></select>
並將<form>
的action屬性更改為index.php
僅和method='get'
因此,一旦提交表單,所有數據都將通過get方法發送到您的php頁面(在本例中為index.php),您可以使用$_GET['foobar']
獲取數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.