0

I have a select, lets call it A. When i choose an option from A, with ajax, i load an another select with options into a div. Lets call this second select B.

I have some ajax onchange code on B, but it does nothing, and it gives no error also.

I think, the "site doesnt see the B select", because it isnt in the source code, ajax loads it into a div.

What would be the solution for this?

$('#fizetes_select').on('change', function() {
    var SelectedValue = this.value;
    if(SelectedValue != 0 )
    {
        $.ajax({
             type: 'POST',
             url: 'files/get_fizetes_text.php',
             data: { id: SelectedValue },
             dataType: "html",
             cache: false,
             beforeSend: function(){
                $('#preloader_fizetes').show();
             },
             success: function(data)
             {
                 var result = $.trim(data);
                 $('#fizetes_result').html(result);
             },
             complete: function(){
                $('#preloader_fizetes').hide();
             }
        });
    }
    return false;
});

Thats the onchange code for the B select, i only want to display some text with it. The ID-s are correct, i didnt write it bad, i chekced. Its in document ready.

KissTom87
  • 87
  • 1
  • 10
  • 1
    use `$(document).on("change","#myId",function(){ ... })` instead of `$("#myId").on("change",function(){...})` since your tag of id `myId` is created dinamically – Stéphane Ammar Dec 26 '17 at 16:59

1 Answers1

1

Are you sure #fizetes_select isn't entering the DOM after this .on() declaration?

Try using document event binding with a targeted element instead.

$(document).on('change', '#fizetes_select', function(e) { 
  // do your thing here
});
SISYN
  • 2,209
  • 5
  • 24
  • 45
  • I tryed this, but still nothing. The js code is at the bottom of the page, before the closing body tag. – KissTom87 Dec 26 '17 at 17:03
  • I understand you are new, but "I tried this but still nothing" doesn't give anyone any information. It also seems like you are attempting to simply copy and paste someone's answer without caring to understand any of it. You need to read the rules of StackOverflow before asking questions because you should be posting all your code samples and specific error messages as to what is not working. – SISYN Dec 26 '17 at 17:13