0

We need to bind such like two way binding . When i change value at also display value in content using Javascript or Jquery..

function myFunction() {
  var val = '';
  val = document.getElementById("text1").value;
  document.getElementById("demo").innerHTML = document.getElementById("demo").innerHTML + val;
}
<p>Select a new car from the list.</p>
<input type='text' id="text1" onKeyup="myFunction()">

<p>When you select a new car, a function is triggered which outputs the value of the selected car.</p>

<p id="demo"></p>

If you any idea then help me !!! Thank you in advance

4
  • have you heard about KnockoutJS or AngularJS? Those are better options for your case Commented Sep 22, 2016 at 19:14
  • where is mySelect id? Commented Sep 22, 2016 at 19:15
  • 1
    Your code is working what is wrong here? Commented Sep 22, 2016 at 19:20
  • @Paritosh Thanks for Give me suggestion but, i need in jquery or javascript. Commented Sep 22, 2016 at 19:42

2 Answers 2

1

Rather than appending the value of demo you should just be replacing the value with the value in the textbox.

document.getElementById("demo").innerHTML = document.getElementById("text1").value;

https://jsfiddle.net/03gkm4wh/


Also:

onKeyup attribute should be lowercase - onkeyup.

mySelect isn't referenced.

Sign up to request clarification or add additional context in comments.

Comments

1

Something like this?

function myFunction() {
    var val = document.getElementById("text1").value;
    document.getElementById("demo").innerHTML = val;
}
<p>Enter data:</p>
<input type='text' id="text1" onKeyup="myFunction()">

<p>When you input new data, a function is triggered which updates the HTML.</p>

HTML Output:
<hr>
<p id="demo"></p>

1 Comment

You should explain what was wrong with the original code, and how you fixed it.

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.