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.

Tamil Selvan C
  • 19,232
  • 12
  • 49
  • 68

3 Answers3

3

Try

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

function msj(str) {
  $("#txt").val(str); // jQuery
}
Tamil Selvan C
  • 19,232
  • 12
  • 49
  • 68
0

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

$("#input-txt").val(str); 
Claudio Redi
  • 65,896
  • 14
  • 126
  • 152
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.

Community
  • 1
  • 1
DACrosby
  • 10,626
  • 3
  • 36
  • 50