Learn free online HTML5, javascript, and jquery Tutorials by Examples

Tuesday 17 June 2014

OnClick value with innerhtml in javascript

---------------------------------------------------

<h1 id="title1">ys</h1>
<input type="text" id="txt"/>
<input type="button" onclick="show()" value="click" />   

<script>
    function show() {
    var myvar = document.getElementById('txt').value;
    console.log(myvar)
    if(myvar.length == 0){
        alert('plz enter the value');
        return;
        }
        var mytitle = document.getElementById('title1');
        mytitle.innerHTML = myvar;
    }
</script>

---------------------------------------------------

No comments:

Post a Comment