[Fixed]-Select option not working for Modal

1👍

The problem was that the code was under the $(document).ready(function()) which is why it was not able to get the value at that time. I took my functions outside the document.ready method and its working now!

0👍

Make sure that your javascript is running without error and it is above your modal. Your modal is getting compiled before your javascript runs and so that data cannot be fetched when you click on modal.

👤Jaimin

0👍

I’m an not familiar with Django templates, but your markup suggests perhaps the template is not being rendered until openModal() is called. Is this the case?

If so, then you would need to run your auto-select code after the modal’s <option> elements have been rendered.

To test this you could put a console.log inside your for loop, to check which options are available when the click event happens.

for (var i=0; i<product_select.options.length; i++){    
    console.log(product_select.options[i])
}

Leave a comment