1

I'm currently creating a function that goes through an array and checks to see if values exist. If values do exist then it's suppose to allow the checkboxes to be clicked. The problem is for some reason it isn't enabling the checkboxes. It is going into the if statement as the alert is printing but it isn't changing the attributes. Changing from attr to prop makes no difference in this case either way it isn't doing what its suppose to. This is the updated code I have..

var values = this.value();
var total = ["1", "2", "3", "4", "5"];
var group = "";
for (number in values) {
            if ($.inArray(values[number], total) != -1) {
                group = "group" + values[number];
                $("input." + group).prop("disabled", false);
               alert("Group: " + group + " Values: " + values[number] + "   The values DO match");
            }
            else {
                group = "group" + values[number];
                $("input." + group).prop("disabled", true);
                $("input." + group).prop("checked", false);
                alert("Group: " + group + " Values: " + values[number] + "   The values do not match");
            }

        }

Now the code I'm listing below completely works. The only difference is hardcoded class values versus variables above.

if ($.inArray("1", values) != -1 || $.inArray("2", values) != -1) 
{
    $("input.group1").prop("disabled", false);
}
else 
{
    $("input.group1").prop("disabled", true);
    $("input.group1").prop("checked", false);
}

I am using Kendo UI MVC. I've copied the source information for the Multiselect. Here is the JFiddle with the code. http://jsfiddle.net/gS2C8/

Alexender
  • 61
  • 1
  • 6
  • Sorry about that.. This is the variables prior... – Alexender Jul 09 '14 at 16:44
  • Just in case it's an array (I don't know what `this.value()` does), [you should not use `for in`](https://stackoverflow.com/questions/500504/why-is-using-for-in-with-array-iteration-such-a-bad-idea) – Bergi Jul 09 '14 at 16:47
  • That's an easy enough change. And while it's flagged as it's been answered it doesn't solve my initial question. The 2nd code that has the attributes hardcoded into it works but the one that uses variables does not. It doesn't make much sense. – Alexender Jul 09 '14 at 16:50
  • Opps, I didn't notice that the second snippet works; sorry then. Still, you should use `.prop` instead of `.attr` for `disabled` and `checked`. – Bergi Jul 09 '14 at 16:56
  • Updated to that. Also added the JSFiddle to show you how the code sort of looks. – Alexender Jul 09 '14 at 17:03
  • 2
    a jsfiddle that doesnt repro the problem isn't really helpful – Robert Levy Jul 09 '14 at 17:11
  • @RobertLevy unfortunately I'm not entirely sure how to get jsfiddle to work with Kendo. – Alexender Jul 09 '14 at 17:20
  • so...this doesn't make any sense. if you look at $("input." + group) in the debugger, does that refer to what you think it does? $("input." + group).length? – Robert Levy Jul 09 '14 at 17:23
  • If I look at $("input." + group) in the debugger (group = "group1") the information that's produced is the same as $("input.group1") which is what I want. That's the confusing part to me. It doesn't make much of any sense to me. – Alexender Jul 09 '14 at 17:31
  • @Alexender While less helpful, if you can't get the Fiddle to work, maybe link to the original source (if possible). – Gary Jul 09 '14 at 20:49
  • I would love to Gary but unfortunately it's against company policy to show our source code. Hence why everything that has "some" information has been stripped out to the bare bones. I think as much as I absolutely hate it I'll just have a terrible disgusting long set of if/else statements. – Alexender Jul 09 '14 at 23:44

0 Answers0