0

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>
3
Contributors
9
Replies
35
Views
3 Years
Discussion Span
Last Post by nadiam
0

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

0

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 :)

Edited by nadiam

0

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>

0
<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>
0

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> 
0

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>
0

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?

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.