dimanche 21 février 2016

Disable submit button until atleast one checkbox is checked

I have a foreach loop to generate checkboxes and I want to make sure that the submit button remains disabled until atleast one checkbox is checked by the user. But the button remains disabled even after a checkbox is checked.

enter image description here:

Here's my jsp file

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ift.tt/kTyqzh">

<%@ taglib uri="http://ift.tt/QfKAz6" prefix="c"%>
<%@ taglib uri="http://ift.tt/IED0jK" prefix="form"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<link rel="stylesheet" href="bootstrap.css" />
<script
    src="http://ift.tt/1GAqVWa"></script>

<link rel="stylesheet"
    href="http://ift.tt/1JetChn">
<script
    src="http://ift.tt/1ROJ5xx"></script>
<script
    src="http://ift.tt/1RY4jZJ"></script>

<script>
    $('#myform input:checkbox').change(function() {
        var a = $('#myform input:checked').filter(":checked").length;
        if (a == 0) {
            $('.btn').prop('disabled', true);
        } else {
            $('.btn').prop('disabled', false);
        }
    });
</script>

<style type="text/css">
body {
    background: #CCFFCC;
    !
    important;
}
/* Adding !important forces the browser to overwrite the default style applied by Bootstrap */
</style>

<title>Resolve</title>
</head>
<body>
    <h2>Hi There!</h2>
    <h3>Browse through all unresolved issues and choose to resolve
        some:</h3>
    <div style="background-color: transparent; !important"
        class="table-responsive">
        <div class="btn-toolbar pull-right">
            <div class='btn-group'>
                <a href="back"><button class="btn btn-primary btn-lg">Back</button></a>
            </div>
        </div>
        <table class="table">
            <thead>
                <tr>
                    <th>Issue Id</th>
                    <th>Description</th>
                    <th>Status</th>
                    <th>Resolved?</th>
                </tr>
            </thead>

            <form:form class="form-horizontal" modelAttribute="ticketForm"
                action="${pageContext.request.contextPath }/contact/resolveissue"
                method="get" id="myform">

                <c:if test="${not empty form}">

                    <c:forEach var="listValue" items="${form}">
                        <tr>
                            <td>${listValue.ticketId}</td>
                            <td>${listValue.description}</td>
                            <td>${listValue.status}</td>
                            <td>
                                <div class="col-lg-10">
                                    <input type="checkbox" name="resolve"
                                        value="${listValue.ticketId}" class="form-control">
                                    <form:errors path="resolve"></form:errors>
                                </div>
                    </c:forEach>
                </c:if>

                <div class="btn-toolbar pull-right">
                    <div class='btn-group'>
                        <button type="submit" class="btn btn-primary btn-lg"
                            disabled="disabled">Resolve</button>
                    </div>
                </div>




                <!--                <button type="submit" class="btn btn-primary btn-lg center-block">Resolve</button>
 -->
            </form:form>


        </table>

    </div>

</body>
</html>




Aucun commentaire:

Enregistrer un commentaire