0

Adding the insertion of input type text into the div title on the same screen. Attempted broken function to they turn the input into a variable and use it to fill in the div.

<body>
<div class="form">
Form <br><br>
<form name="input" action="javascript:alert(titleValue);">

Title: <input type="text" name="title" class="titleInsert">

<input type="submit" value="Submit">

</form>

</div>

<div class="offer_display">

<div class="title" id= title></div>
</div>

</body>

<script>
var titleValue="";
$('#titleInsert').on("change", function () {
titleValue=$(this).val();
$("#title h3").text("titleValue");
});

</script>
</html>

3 Answers 3

1

Another problem with you code is, that you have to use "input" event and not "change".

See working code on fiddle: http://jsfiddle.net/z037qv3n/

<body>
   Form <br><br>
   <form name="input" action="javascript:alert(titleValue);">
   Title: <input type="text" name="title" id="titleInsert">
   <input type="submit" value="Submit">
</form>

<div class="title" id="title"></div>
</body>

<script>
var titleValue="";
$('#titleInsert').on("input", function () {
  titleValue=$(this).val();
  $("#title").text(titleValue);
});

</script>
</html>
Sign up to request clarification or add additional context in comments.

Comments

0

Change your code for $('div.title').html(titleValue);

Comments

0

Live Demo : JSFIDDLE

You have to include jQuery library in your head section like this

<script src="http://code.jquery.com/jquery-1.10.2.js"></script>

There are lot of mistakes in your code please see below:

First mistake you should put your jQuery inside ready function.

Second mistake there is no such id #titleInsert it is a class so you have to do .titleInsert

Third mistake there is no tag h3 in #title

Fourth mistake you should use .keyup event instead .change event

Replace your jQuery code with following :

<script type="text/javascript">

$(document).ready(function(){

var titleValue="";
$('.titleInsert').on("keyup", function () {
titleValue=$(this).val();
$("#title").text("titleValue");
});

});

</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.