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 of select.
  • div row element , parent of live_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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -