Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...Can only check / uncheck a checkbox onceCan only check / uncheck a checkbox once
Previous
 
Next
New Post
6/13/2017 8:53 AM
 

I have a curious issue.  Testing my JS as I go, found that I can only check and un-check a checkbox once.

Here is my HTML.  I've tried both registering with a script tag and registering with the dnn minification process.  No joy.  With Chrome Dev Tools the same thing happens.  I can check it with the attribute set true, uncheck it with the attribute set false.  Subsequent tries don't work.

This doesn't happen at work with straight up ASP.Net sites using JS.  This must be something peculiar to user controls.

Here is the js I'm testing with:

// JavaScript source code

$(function () {

$('#chkDetails').attr('checked', true);

$('#chkDetails').attr('checked', false);

$('#chkDetails').attr('checked', true);

$('#chkDetails').attr('checked', false);

$('#chkDetails').attr('checked', true);

});

HTML

<%@ Control Language="C#" AutoEventWireup="false" CodeBehind="TestForm2.ascx.cs" Inherits="Durthaler.Modules.FirstDALMVC.TestForm2" %>

<%--<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.Web.Client.ClientResourceManagement" Assembly="DotNetNuke.Web.Client" %>

<dnn:DnnJsInclude runat="server" FilePath="/DesktopModules/MVC/FirstDALMVC/resources/javascript/settings.js" />

<dnn:DnnJsInclude runat="server" FilePath="/DesktopModules/MVC/FirstDALMVC/resources/javascript/common.js" />--%>

<script type="text/javascript" src="<%=ResolveUrl("~/DesktopModules/MVC/FirstDALMVC/resources/javascript/settings.js") %>"></script>

 

<div class="container">

<h6>Supress Columns</h6>

<div>

<div class="row">

<label for="chkDetails" class="col-md-1">Details</label>

<input id="chkDetails" type="checkbox" class="col-md-1" />

<label for="chkPartNum" class="col-md-1">Part #</label>

<input id="chkPartNum" type="checkbox" class="col-md-1" />

<label for="chkCommercialPartNum" class="col-md-1">Commercial Part #</label>

<input id="chkCommercialPartNum" type="checkbox" class="col-md-1"/>

<label for="chkVendor" class="col-md-1">Vendor</label>

<input id="chkVendor" type="checkbox" class="col-md-1" />

<label for="chkQuantity" class="col-md-1">Quantity</label>

<input id="chkQuantity" type="checkbox" class="col-md-1" />

<label for="chkAvailableStock" class="col-md-1">Available Stock</label>

<input id="chkAvailableStock" type="checkbox" class="col-md-1"/>

</div>

<div class="row">

<label for="chkUnitCost" class="col-md-1">Unit Cost</label>

<input id="chkUnitCost" type="checkbox" class="col-md-1"/>

<label for="chkSaleCost" class="col-md-1">Sale Cost</label>

<input id="chkSaleCost" type="checkbox" class="col-md-1"/>

<label for="chkExpediteFee" class="col-md-1">Expedite Fee</label>

<input id="chkExpediteFee" type="checkbox" class="col-md-1"/>

<label for="chkQuote" class="col-md-1">Quote</label>

<input id="chkQuote" type="checkbox" class="col-md-1"/>

<label for="chkOrder" class="col-md-1">Order</label>

<input id="chkOrder" type="checkbox" class="col-md-1"/>

</div>

</div>

<h6>Search Providers</h6>

<div class="row">

<div class="col-md-4">column 2</div>

<div class="col-md-4">column 3</div>

<div class="col-md-4">column 4</div>

</div>

</div>


 
New Post
6/13/2017 9:36 AM
 
Michael,

should the function not only swith the checkbox state? Your function turns it on and off several times leaving it on true at the end. Shouldnt it be something like

Checkbox.Checked = !(CheckBox.Checked);

But this is the default behaviour of checkboxes, so what is the intention of the script?

Happy DNNing!
Michael


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
6/13/2017 11:24 AM
 
I could have said that better.

 

I am just testing it at this point. What I'm saying is? I can check It True by code, one time and then I can check it. False by code, one time and then repeating the process doesn't work.

 

 

Only the first 2 lines work. They should all work.

 

 

Any attempt to check or uncheck. The box after it's been checked true once and then checked false once doesn't work.

 

How can that possibly be correct function?

 

 

I just went into a totally different application and used straight javascript rather than jquery. I can check and uncheck a checkbox as many times as I want.

 

 

It's not working here and I wanna know why that is before I proceed with other coding.
 
New Post
6/13/2017 11:39 AM
Accepted Answer 
Assuming you are on jQuery 1.6+. To use the value in the DOM you should be using prop (for property) not attr.

From http://api.jquery.com/attr/

"To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method."

Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
New Post
6/13/2017 7:10 PM
 

Hmm... quite curious that the first 2 calls with .attr() worked :)

Thanks, that was exactly it.  I use jQuery at work, the .attr() method works so that was what I was used to.

Appreciate the fast response, it was really a big help.

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...Can only check / uncheck a checkbox onceCan only check / uncheck a checkbox once


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out