hey guys, so i want to disable the input button function unless checbox is checked. i found this forum and it sorta worked. the button is disabled when no checkbox is checked but it stays disabled even after checkbox is checked.

this is the html:

<input type="button" id="del_event" name="del_event" value="Delete Event" disabled="disabled"/>



<input type='checkbox' name='check' id='check' onclick='checkSubmit(this, 'del_event')' value='y'/>

this is the js:

<script type="text/javascript">
function checkSubmit(ele, id) {
    x = document.getElementById(id);
    if (ele.checked == true) x.disabled = false;
    else x.disabled = true;
}
</script>

Recommended Answers

All 9 Replies

try this command:

 var chkbox = $("#check"),
                button = $("#del_event");
           button.attr("disabled","disabled");

            chkbox.change(function(){
                if(this.checked){
                    button.removeAttr("disabled");
                }else{
                    button.attr("disabled","disabled");
                }
            });

hope this helps

i tried a coding similar to that as well and it didn't work. the button is still disabled even if checkbox is checked. thank you for taking the time though joshua :)

ummmm..
do you have the links for the jquery first?
like this
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

<script type="text/javascript" src="js/jquery 1.10.2.js"></script>



<script type="text/javascript" src="js/jquery-ui-1.10.4.custom.js"></script>
<script type="text/javascript" src="js/jquery-ui1.10.4.custom.min.js"></script>

your using many plug-in's
maybe your plug-ins are the problem there
the code that i posted here work in my project

Can you try the below code

<input type="submit" id="del_event" name="del_event" value="Delete Event" />



<input type='checkbox' name='check' id='check' onclick="dis_enable_submit()" value='y'/>


<script type="text/javascript">

function initthis()
{
document.getElementById("del_event").disabled=true;
}

function dis_enable_submit()
{
if(document.getElementById("check").checked == 1)
{
document.getElementById("del_event").disabled=false;
}
else
{
document.getElementById("del_event").disabled=true;
}
}

window.onload=initthis;
</script> 

i will try that soon. thanks rpv_sen. But i didnt mention that my checkbox is echoed from php.

<tbody class="tbody-event-list-table2">
                <?php
                    require "connection.php";

                    $check = mysql_query("SELECT event_name,event_date,event_time,event_venue FROM event") or die(mysql_error());
                    if(mysql_num_rows($check) > 0)
                    {
                        while($row = mysql_fetch_array($check))
                        {
                            $name = $row['event_name'];
                            $date = $row['event_date'];
                            $time = $row['event_time'];
                            $venue = $row['event_venue'];

                            echo 
                            "<tr>
                                <td><input type='checkbox' name='check' id='check'/><a href=''>$name</a></td><td>$date</td><td>$time</td><td>$venue</td>
                            </tr>";
                        }
                    }   
                    else
                        {
                            echo 
                            "<tr>
                                <td colspan='4'>There Are No Events.</td>
                            </tr>";
                        }
                ?>
            </tbody>

it works now(with either coding), thank you. but im having another issue that i don't know how to get around. I want not a specific one checkbox but IF a checkbox or multiple checkboxes are checked the button, which is a delete button, will be enabled. the issue im having is that the delete button is only enabled when the first checkbox is checked. say for example the second or third checkbox were checked the delete button is still disabled unless the first checkbox is checked as well.

is there a way around this?

changed id="del_event" to class="del_event". thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.