I think my JQuery knowledge is a little lacking.
On my page I have 0 or more hidden variables that look like this.
<input type='hidden' class='defaultTickedStatus' value='INACTIVE' />
<input type='hidden' class='defaultTickedStatus' value='ACTIVE' />
They can be accessed via the selector $(“.defaultTickedStatus”)
I also have a number of checkboxes in an element like this
<div id="checkboxes">
<input type="checkbox" value="INACTIVE" id="checkbox1" tabindex="30430">
<input type="checkbox" value="ACTIVE" id="checkbox1" tabindex="30430">
<input type="checkbox" value="SUBMITTED" id="checkbox1" tabindex="30430">
<input type="checkbox" value="FINALISED" id="checkbox1" tabindex="30430">
...
</div>
They can be accessed via the selector $(“#checkboxes input”)
What I would like to do is when the user clicks a button, I want it go through all of the checkboxes and for the ones that have a value which equals one of the values in the hidden tags, then to check it.
However, being a little unfamiliar with JQuery, I’m unfamiliar with how to accomplish this. This is what I have so far…
$("#checkboxes input").each(function (index, Element)
{
$(".defaultTickedStatus").each(function (i2, status)
{
if (status.value == Element.value)
{
$(status).selected(true);
}
});
});
It’s getting to the $(status).selected(true) part but for some reason, it does not seem to work. Also, I’m positive there is a much easier way to do this through Jquery.
Wonder if anyone can help me.
Thanks
Be carefull, you can’t have 4 times
id="checkbox1". Also, there is no need to have 2 nested.each(function()if you use the selectorinput[value="foo"]Here is how you can do it:
working jsFiddle