php - jQuery Custom add attribute -
what trying if value of key matches php code want add selected attribute in option. possible collaborate php , jquery?
    $('#vessel_sub_category_id').append("<option value=" + key + " "if(key == <?php echo $select_update['vessel_sub_category_id']; ?>){'selected';}" >" + value + "</option>");       
yes is. need put quotes around string echo in php :)
$('#vessel_sub_category_id').append('<option value="' + key + '"' + if(key == '<?php echo $select_update['vessel_category_id']; ?>'){' selected';}+' >' + value + '</option>');    there smarter way achieve this:
- make sure php short tags enabled
 - use ternary operators
 
it this:
$('#vessel_sub_category_id').append('<option value="' + key + '"'+ (key == '<?=$select_update['vessel_category_id'];?>'?' selected':'')+' >' + value + '</option>');   update: forgot + before if , afterwards
Comments
Post a Comment