user1071891
user1071891

Reputation: 3

Copy Text from Input form into DIV

I want to create 1 input field and one Div. When u write text in the Input and hit the button i want the text to be displayed in the DIV. Its so simple but it just won't work.. i hope someone can do this easy task for me. I tried last:

<form>
        Bearbeitungstext: <input id="textInput" type="text"><br>
        <input type="button" value="text einbinden" onclick="$('texxxt').val($('#textInput').val())">
</form>

    <div id="texxxt">

    </div>

Upvotes: 0

Views: 95

Answers (3)

Roshni Bokade
Roshni Bokade

Reputation: 343

 Bearbeitungstext:
        <input id="textInput" type="text"/><br>
        <input type="button" value="text einbinden" onclick="$('#texxxt').html($('#textInput').val())"/>
        <div id="texxxt">

to change DIV content we use html() not val()

Upvotes: 0

James Taylor
James Taylor

Reputation: 25

This can be done with php $_GET($whatever); also, to do this you will need the name="whatever" on the input field.

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67197

Try to use id selector properly,

$('#texxxt').text($('#textInput').val());

Also you have to use .text() instead of .val(), .val() is not a function for div elements. It is for form elements which are having value property.

And the best approach for your case would be binding an explicit event handler,

var div = $("#texxxt"),inp = $("#textInput");
$("form button").click(function(e){
  e.preventDefault();
  div.text(inp.val());
});

Upvotes: 1

Related Questions