提交按钮与条件链接 [英] Submit button with contingent links

查看:83
本文介绍了提交按钮与条件链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定。我不知道我在做什么。我要回去帮助人们找工作。我在小提琴中运行了所有东西,并将它移植到两个不同的编辑器中,一切都显示正常,但没有任何反应,没有警报,也没有onclick提交。我在我的笔记本电脑上试了一下,两页用profilebannerIE显示出来,另一页用html显示。再次感谢。

jquery的新手。我们有一个表格,我们希望人们填写和提交。表格并不难创建,但现在我们希望它做一些特殊的事情。我已经研究并尝试了3天不同的事情,这是我最后的努力。很多论坛的想法都非常聪明,我相信你们可以在瞬间完成这个工作。

我们正在尝试将下列表单上的提交按钮转到网站1,如果单击了七个或更多单选按钮是。如果有少于7个是的答案,我们希望它转到网站2。

 < html> 
< head>
< meta content =text / html; charset = ISO-8859-1
http-equiv =content-type>
< title> Survey< / title>
< / head>
< body>
< h1 style =text-align:center;>< big>< span
style =font-family:Arial Unicode MS; background-color:white; color:rgb (0,0,153);>调查< / span>< / big>< / h1>
< div
style =text-align:center; font-family:Arial Unicode MS; color:rgb(0,0,153); font-weight:bold;>< big>请
回答以下问题,然后点击页面底部的提交按钮。< / big>< / div>
< form method =postaction =http://www.workintexas.com
name =客户调查>< br>
您目前是否在职?< br>
< input name =Employedvalue =Yestype =radio>是< br>
< input name =Employedvalue =Notype =radio>否< br>
< br>
您是否有足够的文件来支持您在美国工作的授权?< br>
< input name =Documentsvalue =Yestype =radio>是< br>
< input name =Documentsvalue =Notype =radio>否< br>
< br>
你有简历吗?< br>
< input name =Resumevalue =Yestype =radio>是< br>
< input name =Resumevalue =Notype =radio>否< br>
< br>
您有可靠的交通吗?< br>
< input name =transportationvalue =Yestype =radio>是< br>
< input name =transportationvalue =Notype =radio>否< br>
< br>
您是否拥有高中文凭或同等学历?< br>
< input name =Diplomavalue =Yestype =radio>是< br>
< input name =Diplomavalue =Notype =radio>否< br>
< br>
您是否拥有职业执照,认证或高级教育?< br>
< input name =Certvalue =Yestype =radio>是< br>
< input name =Certvalue =Notype =radio>否< br>
< br>
您是否失业超过6个月?< br>
< input name =Unemployedvalue =Yestype =radio>是< br>
< input name =Unemployedvalue =Notype =radio>否< br>
< br>
您在过去两年中有超过三份工作吗?< br>
< input name =Jobsvalue =Yestype =radio>是< br>
< input name =Jobsvalue =Notype =radio>否< br>
< br>
您是否有合适的面试服装?< br>
< input name =Clothingvalue =Yestype =radio>是< br>
< input name =Clothingvalue =Notype =radio>否< br>
< br>
您是否有犯罪背景?< br>
< input name =Backgroundvalue =Yestype =radio>是< br>
< input name =Backgroundvalue =Notype =radio>否< br>
< br>
< input name =Submitvalue =Submittype =submit>< small>< br>
< br>
< br>
< / form>
< / body>
< / html>


解决方案

仅供将来参考,还有一个叫做jsFiddle您可以使用它来为我们提供更好的代码: jsFiddle



我为你提供了一个快速的解决方案,让你开始这里

p>

  var responding_yes = 0; 
$(input [type = radio]:checked)。each(function(){
if($(this).val()===Yes){
answers_yes ++;
}
});
if(answers_yes> = 7){
location.href =7或更多网站.html;
} else {
location.href =小于7 website.html;

$ / code>



完整标记



这是您可以使用的标记(使用CDN提供的jQuery库),您的标记需要一定的工作量,但是您已经明确表示您是初学者,所以我会给您带来一些帮助。看看你是否有更进一步的地方。

 < html> 
< head>
< meta content =text / html; charset = ISO-8859-1http-equiv =content-type>
< title> Survey< / title>
< / head>
< body>
< h1 style =text-align:center;>
< big>< span style =font-family:Arial Unicode MS; background-color:white; color:rgb(0,0,153);> Survey< / span><大>
< / h1>
< div style =text-align:center; font-family:Arial Unicode MS; color:rgb(0,0,153); font-weight:bold;>
< big>请回答以下问题,然后点击页面底部的提交按钮。< / big>
< / div>
< form method =postaction =http://www.workintexas.comname =Customer Survey>
< br>您目前有工作吗?< br>
< input name =Employedvalue =Yestype =radio>是< br>
< input name =Employedvalue =Notype =radio>否< br>
< br>您是否有现成的文件来支持您在美国的授权?< br>
< input name =Documentsvalue =Yestype =radio>是< br>
< input name =Documentsvalue =Notype =radio>否< br>
< br>您有简历吗?< br>
< input name =Resumevalue =Yestype =radio>是< br>
< input name =Resumevalue =Notype =radio>否< br>
< br>您有可靠的交通吗?< br>
< input name =transportationvalue =Yestype =radio>是< br>
< input name =transportationvalue =Notype =radio>否< br>
< br>你有高中毕业证书或同等学历吗?< br>
< input name =Diplomavalue =Yestype =radio>是< br>
< input name =Diplomavalue =Notype =radio>否< br>
< br>您是否拥有职业执照,认证或高级教育?< br>
< input name =Certvalue =Yestype =radio>是< br>
< input name =Certvalue =Notype =radio>否< br>
< br>你的失业时间超过6个月吗?< br>
< input name =Unemployedvalue =Yestype =radio>是< br>
< input name =Unemployedvalue =Notype =radio>否< br>
< br>您在过去两年内有超过三份工作吗?< br>
< input name =Jobsvalue =Yestype =radio>是< br>
< input name =Jobsvalue =Notype =radio>否< br>
< br>你有适当的面试服装吗?< br>
< input name =Clothingvalue =Yestype =radio>是< br>
< input name =Clothingvalue =Notype =radio>否< br>
< br>你有犯罪背景吗?< br>
< input name =Backgroundvalue =Yestype =radio>是< br>
< input name =Backgroundvalue =Notype =radio>否< br>
< br>< input name =Submitvalue =Submittype =submit>< small>< br>
< br>
< br>
< / form>
< script type =text / javascripthref =http://code.jquery.com/jquery-1.10.0.min.js>< / script>
< script type =text / javascript>
$(document).ready(function(){
$(input [type = submit])。bind(click,function(e){
e.preventDefault );
var responding_yes = 0;
$(input [type = radio]:checked)。each(function(){
if($(this).val()= ==Yes){
answers_yes ++;
}
});
if(answers_yes> = 7){
location.href =7或更多website.html;
} else {
location.href =小于7 website.html;
}
});
});
< / script>
< / body>
< / html>


Ok. I don't know what I'm doing. I'm going to go back to helping people find jobs. I ran everything in the Fiddle and migrated it over to two different editors and everything shows up fine, but nothing happens, no alerts, no onclick to submit. I tried it on my laptop and two pages showed up one with profilebannerIE on it and the other with the html. Thanks again.

Old man new to jquery. We have a form that we would like for folks to fill out and submit. The form was not difficult to create, but now we would like it to do some special things. I've researched and tried different things for 3 days and this is my last ditch effort. Many of your forum ideas are very clever and I'm sure ya'll can get this to work in a flash. Thanks in advance!

We are trying to get the submit button on the following form to go to "website 1" if seven or more of the radio buttons are clicked "yes". If there are less than 7 "yes" answers we would like it to go to "website 2".

<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
 <title>Survey</title>
</head>
<body>
<h1 style="text-align: center;"><big><span
 style="font-family: Arial Unicode MS; background-color: white; color: rgb(0, 0, 153);">Survey</span></big></h1>
<div
 style="text-align: center; font-family: Arial Unicode MS; color: rgb(0, 0, 153); font-weight: bold;"><big>Please
answer the following questions and click the 'Submit' button at the bottom of the page.</big></div>
<form method="post" action="http://www.workintexas.com"
 name="Customer Survey"><br>
Are you currently employed?<br>
  <input name="Employed" value="Yes" type="radio">Yes<br>
  <input name="Employed" value="No" type="radio">No<br>
  <br>
Do you have readily available, documents to support your authorization to work in the USA?<br>
  <input name="Documents" value="Yes" type="radio">Yes<br>
  <input name="Documents" value="No" type="radio">No<br>
  <br>
Do you have a resume?<br>
  <input name="Resume" value="Yes" type="radio">Yes<br>
  <input name="Resume" value="No" type="radio">No<br>
  <br>
Do you have reliable transportation?<br>
  <input name="transportation" value="Yes" type="radio">Yes<br>
  <input name="transportation" value="No" type="radio">No<br>
  <br>
Do you have a high school diploma or equivalent?<br>
  <input name="Diploma" value="Yes" type="radio">Yes<br>
  <input name="Diploma" value="No" type="radio">No<br>
  <br> 
Do you have an occupational license, certification, or advanced level of education?<br>
  <input name="Cert" value="Yes" type="radio">Yes<br>
  <input name="Cert" value="No" type="radio">No<br>
  <br>
Have you been unemployed longer than 6 months?<br>
  <input name="Unemployed" value="Yes" type="radio">Yes<br>
  <input name="Unemployed" value="No" type="radio">No<br>
  <br>
Have you had more than three jobs within the last two years?<br>
  <input name="Jobs" value="Yes" type="radio">Yes<br>
  <input name="Jobs" value="No" type="radio">No<br>
  <br>
Do you have appropriate interview clothing?<br>
  <input name="Clothing" value="Yes" type="radio">Yes<br>
  <input name="Clothing" value="No" type="radio">No<br>
  <br>
Do you have a criminal background?<br>
  <input name="Background" value="Yes" type="radio">Yes<br>
  <input name="Background" value="No" type="radio">No<br>
  <br>
  <input name="Submit" value="Submit" type="submit"><small><br>
  <br>
  <br>
 </form>
</body>
</html>

解决方案

Just for future reference, there's a nifty tool called jsFiddle that you can use to give us better code to work with: jsFiddle

I've made you a quick one, with a solution that should get you started here

var answered_yes = 0;
$("input[type=radio]:checked").each(function() {
    if ($(this).val() === "Yes") {
        answered_yes++;
    }
});
if (answered_yes >= 7) {
    location.href = "7 or more website.html";
} else {
    location.href = "less than 7 website.html";
}

Full Markup

Here's the markup you can use (with jQuery library included from a CDN), your markup needs a fair bit of work but you've made it clear you're a beginner so I'll throw you a bone. See if you get anywhere further with this.

<html>
<head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title>Survey</title>
</head>
<body>
    <h1 style="text-align: center;">
        <big><span style="font-family: Arial Unicode MS; background-color: white; color: rgb(0, 0, 153);">Survey</span></big>
    </h1>
    <div style="text-align: center; font-family: Arial Unicode MS; color: rgb(0, 0, 153); font-weight: bold;">
        <big>Please answer the following questions and click the 'Submit' button at the bottom of the page.</big>
    </div>
    <form method="post" action="http://www.workintexas.com" name="Customer Survey">
        <br>Are you currently employed?<br>
        <input name="Employed" value="Yes" type="radio">Yes<br>
        <input name="Employed" value="No" type="radio">No<br>
        <br>Do you have readily available, documents to support your authorization to work in the USA?<br>
        <input name="Documents" value="Yes" type="radio">Yes<br>
        <input name="Documents" value="No" type="radio">No<br>
        <br>Do you have a resume?<br>
        <input name="Resume" value="Yes" type="radio">Yes<br>
        <input name="Resume" value="No" type="radio">No<br>
        <br>Do you have reliable transportation?<br>
        <input name="transportation" value="Yes" type="radio">Yes<br>
        <input name="transportation" value="No" type="radio">No<br>
        <br>Do you have a high school diploma or equivalent?<br>
        <input name="Diploma" value="Yes" type="radio">Yes<br>
        <input name="Diploma" value="No" type="radio">No<br>
        <br>Do you have an occupational license, certification, or advanced level of education?<br>
        <input name="Cert" value="Yes" type="radio">Yes<br>
        <input name="Cert" value="No" type="radio">No<br>
        <br>Have you been unemployed longer than 6 months?<br>
        <input name="Unemployed" value="Yes" type="radio">Yes<br>
        <input name="Unemployed" value="No" type="radio">No<br>
        <br>Have you had more than three jobs within the last two years?<br>
        <input name="Jobs" value="Yes" type="radio">Yes<br>
        <input name="Jobs" value="No" type="radio">No<br>
        <br>Do you have appropriate interview clothing?<br>
        <input name="Clothing" value="Yes" type="radio">Yes<br>
        <input name="Clothing" value="No" type="radio">No<br>
        <br>Do you have a criminal background?<br>
        <input name="Background" value="Yes" type="radio">Yes<br>
        <input name="Background" value="No" type="radio">No<br>
        <br><input name="Submit" value="Submit" type="submit"><small><br>
        <br>
        <br>
    </form>
    <script type="text/javascript" href="http://code.jquery.com/jquery-1.10.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("input[type=submit]").bind("click", function (e) {
                e.preventDefault();
                var answered_yes = 0;
                $("input[type=radio]:checked").each(function () {
                    if ($(this).val() === "Yes") {
                        answered_yes++;
                    }
                });
                if (answered_yes >= 7) {
                    location.href = "7 or more website.html";
                } else {
                    location.href = "less than 7 website.html";
                }
            });
        });
    </script>
</body>
</html>

这篇关于提交按钮与条件链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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