I want to set a checkbox having a particular value checked using jquery. Now I am using the following line of code to achieve the goal.
Here it is:
$("input[id=brand_id_][value=" + only_brand_name + "]").prop('checked', true);
Where 'brand_id_' is the checkbox id and 'only_brand_name' is a string comes from other part of code.
Now this approach is working fine where the checkbox value is just a simple string without any white spaces and special characters. For example if the checkbox html is as:
<input class="brand_tag" id="brand_id_" name="brand_id[]" type="checkbox" value="ACC">
And the 'only_brnad_name' is 'ACC', then I can set the checkbox checked without having any issue by the given line of jquery code.
But if the checkbox html is as:
<input class="brand_tag" id="brand_id_" name="brand_id[]" type="checkbox" value="(Reputed)China Make">
And if 'only_brand_name' variable is exactly '(Reputed)China Make', then I am unable to set the checkbox 'checked' by the same line of jquery code. It seems a weird type of issue and got stuck here for a long time.
Please help me to figure out this. Thanks in advance!!!
Aucun commentaire:
Enregistrer un commentaire