Noob_coder Noob_coder - 7 months ago 42
Javascript Question

How to retrieve textbox data from modal

I am using the following bootstrap code to display a modal now i want to get value from the input field .I have tried many ways but failed to get the data using javascript.

<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Forgot Password ?</h4>
</div>
<div class="modal-body">
<p>Enter your employee id below to reset your password.</p>
<input type="text" name="getId" placeholder="Employee id" autocomplete="off" class="form-control placeholder-no-fix">

</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
<button class="btn btn-primary" btn="submt" type="button">Submit</button>
</div>
</div>
</div>
</div>

$(document).ready(function () {

var btnSubmit = $(element).parent().prev().find("#submt");

$(btnSubmit).click(function()
{
//var ids = $('getId').val();
var ids = $(element).parent().prev().find("#getID");
alert(ids);

$.ajax({
url:'rtrv_pass.php',
type:'post'
//data:{uid:},
});
});

});

Answer

I have just modified your click event code..

Jquery:

$('#btnSubmit').click(function () {

        var textFieldVal = $('input[name="getId"]').val();


        $.ajax({
            url: 'rtrv_pass.php',
            type: 'post'
            //data:{uid:},
        });

    });