Mehar
Mehar

Reputation: 2228

How to insert div text to input field?

How to insert Div text to Input field using Jquery through id???

<div id="tmstatus>bla bla</div>

<input type="hidden" name="tm_name" >

any hint???

Upvotes: 0

Views: 1054

Answers (5)

KANAYO AUGUSTIN UG
KANAYO AUGUSTIN UG

Reputation: 2178

I guess this exactly what you need. First you take away the input element and replace it with an empty span element:

<div id="tmstatus">bla bla</div>
<span id="input_holder"></span>

Then run this jQuery code:

$(document).ready(function() {
    var get_val = document.getElementById('tmstatus').innerHTML;
    var element = '<input type="text" value="'+ get_val +'" name="tm_name" />';
    $("#input_holder").html(element);
});

Upvotes: 0

PSR
PSR

Reputation: 40318

<div id="tmstatus>bla bla</div>    
<input type="hidden" id="textBoxId" name="tm_name" >    

$("#textBoxId").val($('#tmstatus').text(););

Upvotes: 2

Syed Osama
Syed Osama

Reputation: 133

var div_val = jQuery("#tmstatus").html();
jQuery("input[name='tm_name']").val(div_val);

Upvotes: 1

Anton
Anton

Reputation: 32581

  $('input[name="tm_name"]').val($('#tmstatus').text());

Upvotes: 0

GautamD31
GautamD31

Reputation: 28763

As my consideration try this

var my_txt = $('#tmstatus').text(); 
$("input[name='tm_name']").val(my_txt);

Upvotes: 0

Related Questions