将表单提交到2个不同的操作页面 [英] Submit form to 2 different action page

查看:206
本文介绍了将表单提交到2个不同的操作页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个可以根据选择框提交到两个不同操作页面的表单。

I would like to have a form that can submit to two different action pages based on a select box.

这意味着如果我在选择框中选择产品,则操作将是产品。 html ,如果我选择用户,操作将是 users.html

Meaning if I select in the select box Products, the action would be products.html, and if I select Users, the action would be users.html

我发现很多例子都有两个提交按钮,但我只需要一个提交按钮。

I have found many examples that have two submit buttons, but I need only one submit button.

任何想法怎么做?

推荐答案

你可以使用jQuery ...

you can use jQuery for that ...

如果选择的值等于某事

将表单属性操作设置为另一个非初始操作

set form attribute action to the other thing not initial action

这当然是伪代码..

这是一个有效的解决方案:

here is a working solution :

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#selectList").change(function(){
        if($('#selectList').val() == 1){
        $("#yourform").attr("action","secondaryaction");
        }
    });
});
</script>
</head>
<body>
<select name="dummy" id="selectList">
<option value="0">foo</option>
<option value="1">bar</option>
</select>

<form id="yourform" action="primaryaction">
bla bla
</form>
</body>
</html>

这篇关于将表单提交到2个不同的操作页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆