• CONTEST ALERT - Experience the power of DDR5 memory with Kingston Click for details

Changing label text using javascript

Status
Not open for further replies.

whoopy_whale

Journeyman
Please suggest me a way to change a label text using javascript.
I have a form with some input elemnts in it.
Whenever the user makes an input into a particular text field,that input should reflect as the text inside the <label> tag...

How can I do it?
Help plz...
 

lywyre

Cyborg Agent
Here it is. The value will be updated after the focus is moved away from the text box. [onblur() also has the same effect]

<form>
<label id="mylabel">No text</label>
<br /><input size="15" id="mytext" onchange="updatelbl()"/>
<br /><input size="15" />
</form>

<script type="text/javascript">
function updatelbl(){
document.getElementById("mylabel").innerHTML = document.getElementById("mytext").value;
}
</script>
 
Status
Not open for further replies.
Top Bottom