2

I have this function:

function msj(str) {
//    display = document.getElementById("txt"); // DOM
//    nodo = document.createTextNode(str);
//    display.replaceChild(nodo,display.firstChild);
$("#txt").html(str); // jQuery
}

The message is displayed here:

<div id="txt">Guess the number between 1 and 10</div>

Then, I want to display the message into a input text form. Anyone knows how to do it?

Many thanks.

1

3 Answers 3

3

Try

<input type="text" id="txt" />

function msj(str) {
  $("#txt").val(str); // jQuery
}
Sign up to request clarification or add additional context in comments.

Comments

0

Assuming you have an input text element with id=input-txt then you could do

$("#input-txt").val(str); 

Comments

0

jQuery

function msj(str){
  $("#txt").val(str);
}

HTML

<input type="text" name="inputField" id="txt" />

Okay, maybe that's a bit overkill with relevant links that answer your question, but they all answer your question.

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.