I'm weak in JavaScript ,, And I'm Using Some project..... So I'm Facing problem | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

I'm weak in JavaScript ,, And I'm Using Some project..... So I'm Facing problem

I want to print a number (1) in input tag, when I click button (1) .. this my problem how am I do this plz any help me

2nd Apr 2022, 1:45 AM
Ashutosh Maurya
Ashutosh Maurya - avatar
2 Respuestas
+ 4
1. In HTML section Give the <input> element an ID to distinct it from other input elements. <input type="text" id="number" /> 2. In JS section Refer to the <input> element by its ID, and assign 1 (number one) as its value document.getElementById( "number" ).value = 1; P.S. If you are writing calculator, try to search for examples in Code Playground. Many people had written calculator, and we can learn by seeing how they do it in code 👍
2nd Apr 2022, 2:59 AM
Ipang
+ 2
https://code.sololearn.com/WaOB8g1HQGSu/?ref=app <!-- html body --> <div> <input type="number" id="number" /> <button onclick="print()">Print</button> <span id="output">null</span> </div> // script var number = document.getElementById("number"); /** * button event function * print input to output */ function print() { var output = document.getElementById("output"); output.innerText = number.value; number.value = ""; }
2nd Apr 2022, 4:58 AM
Calviղ
Calviղ - avatar