我正在尝试创建一个具有多重操作的表单 如果用户选择“选项1”,则操作必须为xxxxx.php,如果用户选择“选项2”,则操作变为另一页
<form method="post" action="irancell-charge.php">
<input type="tel" name="phone" placeholder="093x-xxxxxxx" maxlength="11">
<!-- Select Basic -->
<div class="control-group">
<div class="controls">
<select id="selectbasic" name="selectbasic" class="input-xlarge">
<option>option 1</option>
<option>optoin 2</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-success">send</button>
</form>
答案 0 :(得分:0)
然后
<form id="myform" method="post" action="irancell-charge.php">
<input type="tel" name="phone" placeholder="093x-xxxxxxx" maxlength="11">
<!-- Select Basic -->
<div class="control-group">
<div class="controls">
<select id="selectbasic" name="selectbasic" class="input-xlarge">
<option value="option1">option 1</option>
<option value="option2">optoin 2</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-success">send</button>
</form>
<script type="text/javascript">
document.getElementById('selectbasic').onchange = function(){
console.log('hola');
if (this.value=='option1') {
newAction='option1.php';
} else if (this.value=='option2') {
newAction='option2.php';
} else {
newAction='else.php';
}
document.getElementById('myform').action = newAction;
}
</script>
如果你正在使用jQuery,你可以用$()或jQuery()替换document.getElementById。
答案 1 :(得分:-1)
您可以在标记中使用onclick事件并调用javascript以提交具有不同操作的表单
onclick="submitform1()"
<script type="text/javascript">
submitform1(){
document.myform.action = "xxxxx.php";
document.submit();
}
//for option2 submitform2
submitform2(){
document.myform.action = "yyyyy.php";
document.submit();
}
</script>
或第二种方式
选择标签的onselected事件,你可以调用javascript并传递选项值,根据选项值你可以确定所需的动作