0

I need to call Jquery/JavaScript function when change the categories in OSCLASS.

I used following codes,

<div class="row">
    <label for="catId"><?php _e('Category', 'modern'); ?> *</label>
    <?php ItemForm::category_select(null, null, __('Select a category', 'modern')); ?>
</div>

How i can Call?

leppie
  • 115,091
  • 17
  • 196
  • 297
KarSho
  • 5,699
  • 13
  • 45
  • 78

1 Answers1

1

Function ItemForm::category_select() generate a select html element with class and id catId.

<select name="catId" id="catId"> 
....
</select>

You can add jquery code like this:

$("#catId").change(function(){
    var cat_id = $(this).val();
    if(cat_id != '') {
        alert('Category Id : ' + cat_id );
    }
});

You can add this code directly to the theme page, or via hook wrapping the previous code into a function.

<?php 
function _add_javascript() { 
    if(Params::getParam('page')=='items' && 
(Params::getParam('action')=='post' || Params::getParam('action')=='item_edit') ) {    
?>
<script>
    $("#catId").change(function(){
        var cat_id = $(this).val();
        if(cat_id != '') {
            alert('Category Id : ' + cat_id );
        }
    });
</script>
<?php
    }
}
?>

<?php osc_add_hook('footer', '_add_javascript'); ?>