-1

Having space between string in Value of a checkbox input like Item Two I am not able to set the checkbox to be checked.

<input type="checkbox" id="item2" name="check" value="Item Two">Item Two
$(":checkbox[value=Item Two]").prop('disabled', true);

Is there any way to fix this without changing the value of the input?

$(":checkbox[value=ItemOne]").prop("checked", "true");
$(":checkbox[value=Item Two]").prop('disabled', true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="item1" name="check" value="ItemOne">Item One
<input type="checkbox" id="item2" name="check" value="Item Two">ItemTwo
Suffii
  • 5,694
  • 15
  • 55
  • 92
  • Have you tried replacing the double quotes with backticks (``) and wrapping your value like `value="Item Two"`? – gloo May 26 '22 at 00:00
  • 1
    just put the string in quotes. `":checkbox[value='Item Two']"` – pilchard May 26 '22 at 00:01
  • 1
    Does this answer your question? [How to set HTML value attribute (with spaces)](https://stackoverflow.com/questions/3078192/how-to-set-html-value-attribute-with-spaces) – 2293980990 May 26 '22 at 00:03

1 Answers1

0

You must quote the value if it has spaces

$(':checkbox[value="Item Two"]').prop('disabled', true);
thebjorn
  • 26,297
  • 11
  • 96
  • 138