简体   繁体   中英

how to pass value of textbox to another textbox in a modal using javascript?

I have a textbox in my page, what I want is to do some sort of "preview" using a modal, but i cannot display the value of textbox which I put the information i need. Can someone help me?

I use javascript in doing this, but my modal displays empty textbox.

$('#<%= txtDetails.ClientID %>').on('change', function () {
   $('input[id$="txtKBDecription"]').text($(this).val()); 
}); 
$('#<%= txtIssue.ClientID %>').on('keyup', function () {
   $('input[id$="txtKBSummary"]').text($(this).val()); 
}); 
$('#<%= area.ClientID %>').on('change', function () {
   $('input[id$="txtKBResolution"]').text($(this).val()); 
});

Really need more specifics, but essentially you're going to grab the value form one and put it in the other whenver it changes.

this goes in your preview modal

<input type="text" id="preview" onchange="Copy();">

and this one goes in your final modal

<input type="text" id="final">

and code...

<script>
function Copy()
{
    document.getElementById("final").value = document.getElementById("preview").value;
}
</script>

though it should really be something closer to

<script>
function Copy()
{
    var previewValue = document.getElementById("preview").value;
    if(previewValue != "" /* Or Other Validation */)
         document.getElementById("final").value = previewValue;
}
</script>

you should also consider checking to make sure the elements exist if you are planning on having other people edit the page and/or to make it more robust.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM