这基本上就是标题所说的..我有一个带有选择控件的表单,我想强制表单在更改时回发给自己.
$bmsclientlist = $clientobj->getBMSClientList(); echo '<form name="changebmsid" method="post" action="' . $_SERVER['PHP_SELF'] . '"><select name="bmsid">'; foreach($bmsclientlist as $bmsclient) { $var = ''; if($client['bmsid'] == $bmsclient['id']) { $var = ' selected="selected"'; } echo '<option value="' . $bmsclient['id'] .'"'. $var .'>' .$bmsclient['clientname'] . '</option>'; } echo '</select></form>'; $backupobj = new AdminBackup(); if(isset($_POST['bmsid']){ $statusarray = $backupobj->getStatusTotalsbyId($_POST['bmsid']); }else{ $statusarray = $backupobj->getStatusTotals(); }
我知道它会涉及一些javascript,但我不太清楚如何实现这一点.
任何帮助最感谢!
谢谢,
Jonesy
这是一个< select>这将提交父表格
<form method="post" action="#" name="myform"> <select name="x" onchange="myform.submit();"> <option value="y">y</option> <option value="z">z</option> </select> </form>
您所要做的就是为您的< form>命名.并将onchange事件添加到您的< select> …
亚当是对的.虽然上面的例子很完美,但我会这样做:
使用jQuery,但还有许多其他选项……
<head> <script type="text/javascript" src="jquery.js"></script> <script> $(document).ready(function(){ $('#mySelect').change(function(){ myform.submit(); }); }); </script> </head>
和形式
<body> <form method="post" action="" name="myform"> <select name="x" id="mySelect"> <option value="y">y</option> <option value="z">z</option> </select> </form> </body>