Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That is because asp.net appends some more stuffs to the ids, like ctl, contentplaceholder etc... something like <code>ctl00_ContentPlaceHolder1_chkVehicle</code>. Instead you can do this:</p> <pre><code> function toggleVehicle() { var chkVehicle = '#&lt;%= chkVehicle.ClientID %&gt;'; if ($(chkVehicle).is(':checked')) { $('#divVehicle :input').prop('disabled', false); $('#divVehicle').css({ "background-color": 'transparent' }); } else { $('#divVehicle :input').prop('disabled', true); $('#divVehicle').css({ "background-color": 'gray' }); } } </code></pre> <p>or just assign a class name and select it using the className.</p> <p>or use jquery attribute <strong><a href="http://api.jquery.com/attribute-ends-with-selector/" rel="nofollow">ends-with</a></strong> selector, which could turn out risky though since it does a wildcard match, and slower as well.</p> <pre><code> if ($('[id$="chkVehicle"]').is(':checked')) { .... </code></pre> <p>or as @jsonscript suggests </p> <pre><code>chkVehicle.Attributes.Add("onclick", "toggleVehicle('#" + chkVehicle.ClientId + "');"); </code></pre> <p>and</p> <pre><code> function toggleVehicle(chkVehicle) { if ($(chkVehicle).is(':checked')) { $('#divVehicle :input').prop('disabled', false); $('#divVehicle').css({ "background-color": 'transparent' }); } else { $('#divVehicle :input').prop('disabled', true); $('#divVehicle').css({ "background-color": 'gray' }); } } </code></pre> <p>Also instead of using <code>onclick</code> attribute, bind the handler to the element.</p> <pre><code> $(function(){ //DOM ready $('#&lt;%= chkVehicle.ClientID %&gt;').change(toggleVehicle); }); function toggleVehicle() { var $divVehicle = $('#divVehicle'); if (this.checked) { $divVehicle.css({ "background-color": 'transparent' }); } else { $divVehicle.css({ "background-color": 'gray' }); } $divVehicle.find(':input').prop('disabled', !this.checked); } </code></pre> <p><em>Also use prop instead of attr if you are not using really older version of jquery. That will set these kind of properties better than attr</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload