php - Check chekbox when value of another element is changed -
i want check checkbox when value of "select" changed. no idea wrong code, maybe able see mistake:
var selected; var div_id; $(".live_editor_test").focus(function() { selected = $(this).val(); div_id = $(this).closest("div").attr('id'); }); $(".live_editor_test").blur(function() { if (selected != $(this).val()) { $('#live-assigning_check_' + div_id).attr('checked', true); } });
live_editor_test
class ofselect
.div
row element , parent oflive_editor_test
.live-assigning_check
checkbox id.div_id
increments there 1 row each mysql query.
thanks in advance.
.php :
echo "<span class='content-row live-row-8' style=\"$colorcov\">"; echo "<select class=\"live_editor_test\" name=\"live_editor[$i]\" style=\"width:65px;font-size:10px;\">"; echo "<option value=\"\" selected></option>"; foreach ($storage_access->userauth($row1, $where) $row45) { if ($row45->match_id > '0') { $selected = "selected"; } else { $selected = ""; } echo "<option value=\"$row45->user_id\" $selected>$row45->user_name</option>"; } echo "</select>"; echo "</span>"; echo "<span style=\"width:20px;display:table-cell;\"><input class='checkbox-row' id='live-assigning_check_$i' type='checkbox' name='checked[$i]' ></span>";
use .prop()
instead of .attr()
. use change event select box.
note: assuming '#live-assigning_check_' + div_id
evaluates valid checkbox id.
$(".live_editor_test").change(function() { if (selected != $(this).val()) { $('#live-assigning_check_' + div_id).prop('checked', true); } });
Comments
Post a Comment