Marcia Pereira Reis Marcia Pereira Reis - 1 year ago 86
jQuery Question

Pass variable to input text field in a bootstrap modal

Good morning, I need your help. I am using the code below, where I have a table with colors and clicking on the desired color, opens a modal and the input text is filled with the desired color.

$(document).ready(function () {
$("#myModal").on('', function (e) {
var color = $(e.relatedTarget).data('number');

It turns out that when using the code above, if the page is loaded for the first time, the value comes null when I click the desired color to go to the modal. On the second try, it works. I've been there for days and I will not solve it.

Answer Source

I would try to change your code a bit and use:

var color = $(e.relatedTarget).attr('data-number');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download