0

I have an input field as follows:

<input type="text" id="screen" maxlength="20">

When I type in it, I see text, but there is no change to the html reflecting this.

How do I change the text inside this input using jQuery?

I tried the following but it didn't work:

document.getElementById('screen').innerHTML = "10";

4 Answers4

1

Here's an older example of how to change an input value using JQuery:

jQuery change input text value

$('#screen').val('10');

Else with vanilla Javascript, AlwaysHelping is right with

document.getElementById('screen').value = "10";

lenomis
  • 26
  • 2
0

Use the val method:

$('#screen').val(10);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="screen" maxlength="20">
Andrew Arthur
  • 1,563
  • 2
  • 11
  • 17
0

Set the "value" attribute of an <input> element.

document.getElementById("screen").value = 10;

// or if you select the element with chrome dev tool
$0.value = 10

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#htmlattrdefvalue

jlau
  • 366
  • 1
  • 4
0

In order to do so, you can simply listen to the input cha

function updateInput(inputValue){
console.log("User Input",inputValue)
}
<input  type="text" name="myInput" oninput="updateInput(this.value)" />

nge and print it again on HTML.