user398341
user398341

Reputation: 6577

jQuery live() and change

I have a dilema - created a table of rows which contain text field, dropdown menu and dependent 3rd filed / select.

There's also 'Add new' button which adds new row with default values placed withing these 3 form elements.

Here's the script which changes the third column element depending on the value selected from the preceding select menu:

if ($('.navigation_type').length > 0) {
    $('.navigation_type').live('change', function() {
        var next_cell = $(this).parent('td').next();
        var identity = $(this).attr('id').split('_');
        var type = $(this).val();
        var url = '/pages/c/navigation/a/fetch/id/' + identity[1] + '/type/' + type;
        $.getJSON(url, function(data) {
            if (!data.error) {
                next_cell.html(data.content);
            }
        });         
    });
}

And the 'Add new button' script looks like this:

if ($('.add_navigation').length > 0) {
    $('.add_navigation').click(function() {
        var master = $(this).attr('id').split('_');
        master = master[1];         
        $.getJSON('/pages/c/navigation/a/newrow/master/' + master, function(data) {
            $('#section_' + master).after(data.row);
        });
        return false;
    });
}

The '.add_navigation' button works fine until the point where I change the value in the dropdown - it doesn't do anything - meaning the third column doesn't change depending on the selected value.

I've used live('change') menthod as I thought it should solve the problem, but clearly I'm doing something wrong - any idea what it is?

Upvotes: 0

Views: 4549

Answers (1)

user398341
user398341

Reputation: 6577

Ok - problem solved - it was the other code that was causing the problem! The script above works fine.

Upvotes: 1

Related Questions