So I've got these labels with input checkboxes in it. Now after submit and the form is not accepted it returns here and I want it to select the previous selected box.
<label class="choice" data-id="1"><input type="checkbox" name="group1" value="use your apple1">use your apple<span class="left" ></span></label>
<label class="choice" data-id="1"><input type="checkbox" name="group1" value="Zo maak je van onbekenden klanten1">Zo maak je van onbekenden klanten<span class="left" ></span></label>
<label class="choice" data-id="1"><input type="checkbox" name="group1" value="Multi media feest">Multi media feest<span class="left" ></span></label>
<label class="choice" data-id="4"><input type="checkbox" name="group4" value="Pretwerk OPTIE!">Pretwerk OPTIE!<span class="left" "></span></label>
<label class="choice" data-id="4"><input type="checkbox" name="group4" value="use your apple4">use your apple<span class="left" "></span></label>
<label class="choice" data-id="4"><input type="checkbox" name="group4" value="Snelheid is geld4">Snelheid is geld<span class="left" "></span></label>
<label class="choice" data-id="4"><input type="checkbox" name="group4" value="Fotograferen met je iPhone">Fotograferen met je iPhone<span class="left" "></span></label>
I've already used a hidden field etc. So I've got the returned value of the previously input.
var first = "<?php echo $first ?>";
//in this case I make first the value 'use your apple1'
$("[name$=group1][value=" + first + "]").prop("checked", "true");
So now it should check the box use your apple in group1 But i get the error
jquery.min.js:2 Uncaught Error: Syntax error, unrecognized expression: [name$=group1][value=use your apple1]
name$? should it bename?firstvariable is an empty string,[value=]is causing the error..... and notname$it's valid... attribute ends with selector.. either provide quotes$("[name$=group1][value='" + first + "']")name, but it doesn't work. Looked online somewhere someone usedname$and it worked for mespanelementsname$is valid attribute selector(attribute starts with)