-1
I am following a tutorial to make an AJAX function that detects the change in a <select>
to upload the information to another <select>
. I did the same thing in the video, but mine’s not working.
<script type="text/javascript">
$(document).ready(function() {
$('#aluno_naturalidade_uf').on('change', function(){
alert('Funcionou!');
});
});
</script>
I already put a breakpoint on the line $(document)
, but by clicking to pass the line it jumps straight to </script>
. The imports of scripts from this template I’m using are as follows::
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
The video is this: https://www.youtube.com/watch?v=QTfPlTCsVME The code will be ready around 12:50.
Edit: After you jump to the line </script>
appears this information in Scope:
Found an error in the console?
– Sam
No error on console.
– Leandro Souza
Can elaborate a [mcve] demonstrating in practice the behavior?
– Woss
It is normal to debug go to
</script>
direct, because your code is asynchronous. The function you set inready
will be executed only when the DOM is loaded, not at the time it is scanned by the browser.– Woss
@Andersoncarloswoss I get it. But this point is not running when I switch choose another option in <select>
– Leandro Souza
this script is at the end as the video shows? (before </body>)
– Ana Teixeira
@Anateixeira
– Leandro Souza
Then develop the [mcve] demonstrating this behavior. With the site snippet, button
</>
from the editor, you can do this.– Woss
@Andersoncarloswoss How do I do this? I mean, where can I post this example?
– Leandro Souza
Thanks for the help, I just detected the error. The id "aluno_naturalidade_uf" was duplicated
– Leandro Souza