1

I need to get the value that i typed in the modal input field, when i press enter, the modal will close, and the input value that i typed will be displayed in another input field outside the modal.

    $('#myModal2').on('keydown', function(e)
    {
        if (e.which == 13)
        {
        e.preventDefault();
        var value = $(this).find('td:eq(myInput2)').text();
        document.getElementById("my_member").value = value;
        
        $("[data-dismiss=modal]").trigger(
        {
          type: "click" 
        });
    }
    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <!-- modal button -->
    <button type="button" class="btn btn-outline-secondary" style="background- 
    color:#e6e6e6; " data-toggle="modal" data-target="#myModal2" 
    id="btnproduct2" name="btnproduct2">...</button>

    <!-- input field inside modal -->
    <div class="modal fade" id="myModal2" role="dialog">
    <input type="text" class="form-control" placeholder="ID..." id="myInput2" 
    autocomplete="off" />
    </div>

    <!-- input field outside modal -->
    <input type="text" class="form-control" name="my_member" style="width:75%;" 
    id="my_member" value="" autocomplete="off">
Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
Yong
  • 42
  • 7

1 Answers1

0

Better you handle click event on submit button. Then trigger Button Click Event on Enter Pressing.

Trigger an event on `click` and `enter`

About changing text value after modal is closed. You should use jquery method instead of javascript.

jQuery change input text value

Next time, just try more before asking. Cheers.

P.s: if adding jquery to page, using jquery method instead of javascript.

ルアン
  • 36
  • 6