php - Change Attribute of Child Button -
i have select box. , 2 buttons. buttons disabled. when selectbox changes buttons enabled.
<select class="form-control" id="target_category" name="target_category"> <?php $categories = $categoryobj->deepestcategories(); ?> <option value="-1">kategori seç</option> <option value="0">kategori yok</option> <?php foreach($categories $category){ echo '<option value="'.$category['id'].'">(id: '.$category['id'].') '.$category['category'].'</option>'; } ?> </select> <span class="input-group-btn"> <button disabled="disabled" name="move_category_button" id="move_category_button" class="btn btn-default" type="submit"><span class="glyphicon glyphicon-move"></span> taşı</button> </span> <select class="form-control" id="target_location" name="target_location"> <?php $locations = array('türkiye','Çin','hindistan','nepal','pakistan'); ?> <option value="-1">menşei seç</option> <?php foreach($locations $location){ echo '<option value="'.$location.'">'.$location.'</option>'; } ?> </select> <span class="input-group-btn"> <button disabled="disabled" name="move_location_button" id="move_location_button" class="btn btn-default" type="submit"><span class="glyphicon glyphicon-move"></span> taşı</button> </span>
for short code writing decided merge 2 jquery scripts 1 statement.
but couldn't handle both.
here code.
$('#target_location, #target_category').change(function(){ val = $(this).val(); if (val != -1){ $(this).children('button').removeattr('disabled'); } else { $(this).children('button').attr('disabled','disabled'); } })
your buttons not children of selects, children of sibling.
use .next()
grab sibling button container, .children()
button. also, working disabled
property boolean preferred adding , removing attribute.
$('#target_location, #target_category').change(function(){ var val = $(this).val(); if (val != -1){ $(this).next('input-group-btn').children('button').prop('disabled', false); } else { $(this).next('input-group-btn').children('button').prop('disabled', true); } });
php jquery
No comments:
Post a Comment