วาวาวา
วาวาวา

Reputation: 55

How to receive data from input to div

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

Answers (3)

Amit
Amit

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

user1823761
user1823761

Reputation:

Working jsFiddle Demo

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

Dimitar Dimitrov
Dimitar Dimitrov

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

Related Questions