简体   繁体   English

我有两个复选框“接受”和“拒绝”并提交按钮。 当我单击提交按钮时,它应该检查勾选了哪个复选框

[英]I have two check boxes “Accept” and “Decline” and submit button. When i click on submit button it should check the which check box is ticked

{ field: "Accept", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.AcceptChk), "template": "<input type=\"checkbox\" # if (checkCommentsAccept(data.Comments)) { #disabled=\"disabled\" # } # />" },
{ field: "Decline", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.DeclineChk), "template": "<input type=\"checkbox\" # if (checkCommentsDecline(data.Comments)) { #disabled=\"disabled\" # } # />" },
{ field: "Item", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Item) },
{ field: "PartID", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.PartID) },
{ field: "Description", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Description), width: '300px' },
{ field: "SubPart", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.SubPart) },
{ field: "SubPartDescription", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.SubPartDescription) },
{ field: "BusinessPartner", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.BusinessPartner) },
{ field: "ReqDelTM", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.ReqDelTM) },
{ field: "EarDelTM", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.EarDelTM) },
{ field: "EarDelDate", title: "Ear Del Date", hidden: true },
{ field: "Comments", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Comments) }

When i click submit button it should check accept checkbox is checked or not if is checked then i have some logic.当我单击提交按钮时,它应该检查接受复选框是否已选中,如果选中则我有一些逻辑。 If decline check box is checked then i have some other logic.如果选中了拒绝复选框,那么我还有其他一些逻辑。

This really just comes down to how to stop an event from performing its native behavior.这实际上只是归结为如何阻止事件执行其本机行为。

If a submit button is pressed, the form's submit event is triggered.如果按下提交按钮,则触发表单的submit事件。 So, if your checkbox isn't checked at that time, you'll need to stop the event, which is done with event.preventDefault() .因此,如果当时未选中您的复选框,您将需要停止该事件,这由event.preventDefault()完成。 If the checkbox is checked, simply don't do anything and allow the submit to happen.如果选中该复选框,则只需不做任何事情并允许提交发生。

Here's an example:这是一个例子:

 // Get reference to the checkbox let chk = document.querySelector("input[type='checkbox']"); // Set up event handler on the form document.querySelector("form").addEventListener("submit", function(event){ // Check to see if the checkbox was not checked if(.chk.checked){ event;preventDefault(). // Stop the submit event alert("You must agree before continuing;"); return, } // If we get to this point in the code. the checkox was checked // and the form will submit; });
 <form action="http://example.com" method="post"> <input type="checkbox" name="chkAgree" id="chkAgree" value="agree"> I agree to the terms of this site. <br> <button>Submit</button> </form>

if there is checkbox you might have implemented that only single checkbox is checked right?, other wise there might be possibility that Accept & Declined both checkbox are checked,如果有复选框,您可能已经实现了只选中了一个复选框,对吗?否则可能会同时选中 Accept & Declined 两个复选框,

assuming that you have implemented single select checkbox logic假设您已经实现了单个 select 复选框逻辑

$( "form" ).submit(function( event ) {
  event.preventDefault();
  if($("input[type='checkbox']:checked")[0].val() == 'Allow'){
    // things to done on allowed
  }else  if($("input[type='checkbox']:checked")[0].val() == 'Declined'){
    // things to done on declined
  }else{
    // rest things 
  }
});

you might need to change code a bit, but it will logically work as per your need.您可能需要稍微更改代码,但它会根据您的需要在逻辑上工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击“提交”按钮时如何在JavaScript警报中回显复选框 - How to echo Check Box in JavaScript Alert When Click on Submit Button 我想要一个按钮,单击它时首先要检查密码(如果密码是abcd),而不是显示另一个提交按钮,否则显示警报 - i want button on which when click it first check the password if the password is abcd than shows the another submit button else show an alert 如何检查哪个按钮被打勾jquery / html - How to check which button is ticked jquery/html 如何在没有提交按钮的情况下检查单选按钮是否被选中? - How can i check if the radio button is checked or not without a submit button? 是否可以使用复选框或单选按钮代替提交按钮? - Is it possible to use a check box or radio button in place of a submit button? 单击提交按钮之前,如何检查图像是否已生成? - How do I check if image is generated before clicking submit button? 如何检查是否单击了提交按钮而不是页面上的输入? - How can I check if a submit button is clicked and not an enter press on a page? 提交单选按钮检查表格 - Submit form on radio button check 提交表格并检查是否完整,没有提交按钮 - submit form and check for complete without submit button 我有2个文本框和一个按钮! 当我单击按钮时,它应该在所选文本框中写1,但是我的代码不起作用 - I have 2 text Boxes and one button! When I click on button it should write 1 in the chosen text box but my code is not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM