rhsabbir
rhsabbir

Reputation: 247

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:},
                });
            });

        });

Upvotes: 2

Views: 9542

Answers (4)

madalinivascu
madalinivascu

Reputation: 32354

add a unique id to your submit button:

<button id="uniqueId" class="btn btn-primary" btn="submt" type="button">Submit</button>

$(document).ready(function () {


            $('#uniqueId').click(function()
            {
                var ids = $(this).closest('.modal-dialog').find('input[name="getID"]');
                alert(ids);

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

I suggest you do some reading first about classes,ids,dom,programming in general before you jump into code

Upvotes: 0

Lokesh_Ram
Lokesh_Ram

Reputation: 391

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:},
        });

    });

Upvotes: 1

Manmohan
Manmohan

Reputation: 740

You can get the value of input text field using jquery code

   var input_value = $("#myModal").find('input').val();

Upvotes: 0

Iqbal Pasha
Iqbal Pasha

Reputation: 1316

Try with this below code it may help you to solve issue.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">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 type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
        <button type="button" class="btn btn-primary">Submit</button>
      </div>
    </div>
  </div>
</div>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

Upvotes: 1

Related Questions