Getting output by using <span>

Hello!
I should get the text inputted in the text box using

As I used <span> tag only for decorating text by css, and this time I need it just to output the input value, with no css decoating at all, I ama little bit confused, couldn’t find similar example easy enough to understand.

I tried sth like this, but more just to show what I tend to.
Do I have to incorporate some functions and how?
Please, some tutorial web sites explaining that in simply words maybe??

MANY THANKS IN ADVANCE!!!

<!DOCTYPE html>
<html>

<head>

<script>


var a=document.getElementById("demo").value;
<span id="m">
alert(a);

</span>
</script>

</head>



<body>

<input type="tekst" id="demo">


</body>
</html>
  1. Why your span is inside head? You should move it into body.
  2. JavaScript is event-based language. When you type something in your textfield a various events occurs. You should make your code listen to any of that events and update span.

Example:

<input type="text" id="demo" onkeyup="getElementById('result').innerHTML = this.value" />
<span id="result"></span>

Try it live here: http://jsfiddle.net/3Lhepqwp/

If you want to update span not in “real time”, but only when input loses focus, just replace onkeyup with onchange

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.