#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2014
    Posts
    1
    Rep Power
    0

    Smile Checkbox enable disable option


    Hello,
    i am newbie in coldfusion..can someone help me how to fix this code to enable/disable another checkbox option after first option is true or false. If any suggestion?

    <tr>
    <td><table width="100%" border="0">
    <tr>
    <tr>
    <td>Do you have a car? </td>
    <td><input name="car_type" type="checkbox" value="1">Yes<input name="car_type" type="checkbox" value="0">No</td>
    </tr>
    <tr>
    <td width="100%"></td>
    <td><strong>(Select your car type)</strong></td>
    </tr>
    <tr>
    <td></td>
    <td><input name="car_bmw" type="checkbox" value="1">
    BMW</td></tr>
    <tr><td></td>
    <td><input name="car_mercedes" type="checkbox" value="1">
    Mercedes</td></tr>
    <td></td>
    <td><input name="car_toyota" type="checkbox" value="1">
    Toyota</td>
    <td></td>
    <tr><td>
    </td><td>Others<input name="car_others" type="text" size="20" maxlength="100" /></td>
    </tr>
    <tr>

    Thank you
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    349
    Rep Power
    0
    This is a javascript question, but here you go.


    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test</title>
    <script type="text/javascript" src="scripts/jquery-latest.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    // $('#ownsCar').click(function(){
    // var ownsCar = $(this).val();
    $("form input:radio").change(function() {
    if ($(this).val() == "no") {
    $('#car,#car_others,#submit').attr('disabled', true);
    alert("You do not own a car!");
    } else {
    alert('owns a car');
    $('#car,#car_others,#submit').removeAttr('disabled');
    }
    });
    });
    </script>
    </head>
    <body>
    <form id="cars" name="cars" action="" method="post">
    <table id="cars" width="100%" border="0">
    <tr>
    <td width="200">Do you have a car?</td>
    <td><input type="radio" name="ownsCar" id="ownsCar" value="yes" />Yes
    <input type="radio" name="ownsCar" id="ownsCar" value="no" />No
    </td>
    </tr>
    <tr>
    <td></td>
    <td><strong>(Select your car type)</strong></td>
    </tr>
    <tr>
    <td></td>
    <td><input name="car" id="car" type="checkbox" value="BMW" />BMW</td>
    </tr>
    <tr>
    <td></td>
    <td><input name="car" id="car" type="checkbox" value="Mercedes" />Mercedes</td>
    </tr>
    <tr>
    <td></td>
    <td><input name="car" id="car" type="checkbox" value="Toyota" />Toyota</td>
    </tr>
    <tr>
    <td align="right">Others</td>
    <td><input type="text" name="car_others" id="car_others" size="20" maxlength="100" /></td>
    </tr>
    <tr>
    <td><input type="submit" name="submit" id="submit" value="Submit" />
    </tr>
    </table>
    </form>
    </body>
    </html>
    <cfif isDefined('form.submit')>
    <cfdump var="#form#" label="form">
    </cfif>

IMN logo majestic logo threadwatch logo seochat tools logo