0

I'm using the bootstrap version of x-editable plugin to update the url value present in the table. When a user changes the values of the select box an ajax call is fired to retrieve the corresponding url for the store. Though I unbind the x-editable event everytime before updating the url value, something is not right. The url gets updated only once and then remains the same for the rest of select change events.

<select id="search">
    <option value='1'>store 1</option>
    <option value='2'>store 2</option>
    <option value='3'>store 3</option>
</select>

<table>
    ...
    <tbody>
        <tr>
            <td><a href='#' id='url_qa'></a></td>
        </tr>
    </tbody>
</table>

    // Select box change event
    $('#search').change(function() {
        // ajax call to load the url based on chosen select value
        $.ajax({ 
            url: 'load.php',
            type: 'post',
            dataType: 'json',
            data: {'id': $(this).val()},
        }).done(function(data) {
            $('#url').editable('destroy'); // destroy editable
            $('#url').editable({
                type: 'text',
                pk: 1,
                url: '/post',
                title: 'Enter username',
                value: data['url']
            });
        }).fail(function() {
            alert('Error: Unable to fetch information for the chosen id');
        });
    });

The following happens when I change my select value

  • When I change the select value for the first time, the url is empty and does not get updated.

  • But when I change the select value for the second time the url is gets changed.

  • And for all select value changes after this the second url is not updated at all.

Demo: JSFiddle

DhiwaTdG
  • 748
  • 1
  • 10
  • 26

0 Answers0