如何根据单选按钮的选择启用/禁用表单上的多个提交按钮 [英] How to enable/disable multiple submit buttons on a form depending on selection of a radio button

查看:109
本文介绍了如何根据单选按钮的选择启用/禁用表单上的多个提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列出项目中所有里程碑的表单。
表单有两个提交按钮。一个显示里程碑中的任务。另一个提交按钮应该执行一个脚本来生成所选按钮的燃尽图。
这是我想要做的事情

I have a form that lists all the milestones in a project. The form has two submit buttons. One displays the tasks in the milestone. The other submit button is supposed to execute a script to generate a burndown chart for the selected button. Here is what I want to do


  1. 当页面加载并且没有选择里程碑时,提交
    按钮被禁用—这是实现的。

  2. 当用户选择任何里程碑时,两个提交按钮都会激活
    - 我需要帮助。我知道如何将一个提交按钮的启用/禁用
    与无线电选择相关联。这是两个提交
    按钮,我有问题。
  3. 根据按下哪个按钮,合适的Python脚本
    应该在后台执行。 —一旦我的
    禁用按钮问题完成,我将继续工作。

目前,当页面加载时,提交按钮处于禁用状态。即使在我选择了一个里程碑后,它们也没有被启用。我怀疑,这可能是因为它可能会返回一个提交按钮的数组,可能我需要具有相同的逻辑?任何帮助表示赞赏。这里是代码。

At present, when the page loads, both the submit buttons are in disabled state. And even after I select a milestone, none of them gets enabled. I suspect, it may be because it may be returning an array of submit buttons and may be I need to have logic for the same? Any help is appreciated. Here is the code.

<form action="show_milestone.py" method="POST" name="milestone_form">
<table><tbody><tr>
    <td>Milestone ID</td>
    <td>Milestone Name</td>
    <td>Milestone Start Date</td>
    <td>Milestone End Date</td>
</tr>
<tr>
    <td><input type="radio" name="milestone_id" value="1" onclick="javascript:document.milestone_form.submit.disabled=false"> 1<br></td>
    <td>milestone_1</td>
    <td>03/24/2012</td>
    <td>04/07/2012</td>
</tr></tbody></table>
<p></p>
<input type="submit" name="submit" value="Show Tasks" disabled="">
<input type="submit" name="submit" value="Get Burndown Chart" disabled="">
</form>


推荐答案

这是一个小提琴,

http://jsfiddle.net/bDwxB/1 /

以下是您需要的jQuery和HTML:

And here's the jQuery and HTML you'd need:

<script>
$(document).ready(function(){
    $('input[name=buttonGroup]').change(function(){
        $('input.buttonGroupDependent').attr('disabled', true);
        $('#' + $(this).data().trigger).attr('disabled', false);
    });
});​
</script>

<input type="radio" name="buttonGroup" data-trigger="button1" />
<input type="radio" name="buttonGroup" data-trigger="button2" />
<input type="radio" name="buttonGroup" data-trigger="button3" />

<form action="/echo/json/1">
    <input type="submit" id="button1" value="Button 1" class="buttonGroupDependent" disabled/>
</form>
<form action="/echo/json/2">
    <input type="submit" id="button2" value="Button 2" class="buttonGroupDependent" disabled/>
</form>
<form action="/echo/json/3">
    <input type="submit" id="button3" value="Button 3" class="buttonGroupDependent" disabled/>
</form>​

这篇关于如何根据单选按钮的选择启用/禁用表单上的多个提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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