Reputation: 55
I want to show data to div not textarea how do it..
<script type='text/javascript'>
$(window).load(function () {
$("#pasteable").bind('paste', function (event) {
var $pastable = $(this);
setTimeout(function () {
$("#target").val($pastable.val());
$pastable.val("");
$pastable.focus();
}, 100);
});
});
</script>
Paste here: <input id="pasteable" />
It should show here instead:
<textarea id="target"></textarea>
How to show in this div
<div id="target"contentEditable="true"style="width:300px;height:100px;border:1px #ffccff solid"></div>
Upvotes: 0
Views: 108
Reputation: 15387
Never use same Id in a form
. But if you have some requirement then use as-
$(window).load(function () {
$("#pasteable").bind('paste', function (event) {
var $pastable = $(this);
setTimeout(function () {
$("[id='target']").val($pastable.val());
$pastable.val("");
$pastable.focus();
}, 100);
});
});
Upvotes: 0
Reputation:
Your #target
element, isn't textarea
anymore, so you must use .html()
method instead of .val()
method.
Consider the following markup:
<input id="pasteable" />
<div id="target"contentEditable="true"style="width:300px;height:100px;border:1px #ffccff solid"></div>
And in your JS code:
$(function () {
$("#pasteable").bind('paste', function (event) {
var $pastable = $(this);
setTimeout(function () {
$("#target").html($pastable.val());
$pastable.val("");
$pastable.focus();
}, 100);
});
});
Upvotes: 2
Reputation: 15138
You can't have 2 elements with the same id
on the page. Change either one of them accordingly, for example:
<textarea id="source"></textarea>
And:
<div id="target" contentEditable="true" style="width:300px;height:100px;border:1px #ffccff solid"></div>
Upvotes: 0