speedy
speedy

Reputation: 375

Prototype to jquery function

I have a function for updating multiple selects based on values of another select.
How can I edit this function to use it without prototype just with jquery ?

function replace(val) {
    if (val != 0) {
        $$('select.replace).each(function(e) {
            var aa = e.value.split("_");
            if (aa[0] = val) {
                e.value = val + "_" + aa[1] + "_" + aa[2];
                jQuery("select.replace").trigger("chosen:updated");
            }
        });
    } else {
        alert('Please select a valid value');
        return false;
    }
}

Upvotes: 0

Views: 65

Answers (2)

Miu
Miu

Reputation: 55

Try using .change() when the select value is changed.

$( ".target" ).change(function() {
   // code here
});

Upvotes: 1

antyrat
antyrat

Reputation: 27765

It's simple:

jQuery( 'select.replace' ).each(function() {
    var aa = $( this ).val().split("_");
    if (aa[0] = val) {
        $( this ).val( val + "_" + aa[1] + "_" + aa[2] );    
 //...

Red more about jQuery val() method.

Upvotes: 2

Related Questions