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:

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

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -