user8518202
user8518202

Reputation:

How to append textbox value to another textbox

Here i'm new to jquery please help me how can i assign textbox value to another tex Like

 <b>Enter Some Text</b>   <input type="text" id="TxtHelp" /><br />
        <button id="HelloModal" class="btn">ModalPop</button>

When i Enter Text in textbox & click on button the Span showing value but why texbox not showing

    <span id="Span1"></span><br />
    <input type="text" class="form-control" id="JanMic" /><b>hhh</b>

Jquery

$('#HelloModal').click(function () {
        var txt = $('#TxtHelp').val();
        $('#Span1').append(txt); //Its showing
        $('#JanMic').append(txt);  //Its not showing
    })

Upvotes: 0

Views: 2862

Answers (1)

SilverSurfer
SilverSurfer

Reputation: 4365

Change append() to val() to change the value of the input:

$('#HelloModal').click(function () {
     var txt = $('#TxtHelp').val();
     $('#Span1').append(txt);
     $('#JanMic').val(txt);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<b>Enter Some Text</b>   <input type="text" id="TxtHelp" /><br />
<button id="HelloModal" class="btn">ModalPop</button>

 <span id="Span1"></span><br />
<input type="text" class="form-control" id="JanMic"><b>hhh</b>

Upvotes: 2

Related Questions