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,913
  • 12
  • 49
  • 70

3 Answers3

3

Try

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

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

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

$("#input-txt").val(str); 
Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
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
  • 11,116
  • 3
  • 39
  • 51