Insert Value in Input Value with JS

0

I'm trying to bring a value that when clicking a button brings an input it works but the value does not appear inside the Value of the input so I can not capture this value via PHP. >

Follow the code

link

Button

<a href="#my_modal" data-toggle="modal" data-fornecedor-id="<?php echo $rowPedido->id; ?>"><img src="img/lupa.png"  ></a>

Input

<input type="text" name="idPedido" id="idPedido" value="" />

JS

  $('#my_modal').on('show.bs.modal', function(e) {
var idPedido = $(e.relatedTarget).data('fornecedor-id');

document.getElementById('idPedido').value = idPedido;    

});
    
asked by anonymous 12.07.2016 / 14:43

2 answers

1

To display the value in the 'value' attribute as desired, do the following:

$(document).on("click", ".open-AddBookDialog", function () {
     var myBookId = $(this).data('id');
     $(".modal-body #bookId").attr('value', myBookId );
});

Note that .attr ('value', myBookId) is used instead of .val (myBookId)

link

    
12.07.2016 / 22:17
1

Try it that way and let me know if it worked for you:

$('#my_modal').on('show.bs.modal', function(event) {

  var $target = [];
      $target['fornecedor-id'] = $(event.relatedTarget).data('fornecedor-id');
      $("#idPedido").val($target['fornecedor-id']);

});
    
12.07.2016 / 15:28