Skip to content Skip to sidebar Skip to footer

Javascript Change Value Of Button

How do I change the value of this button? I am looking at a tutorial, but only the url seems to change, and not the button.

Solution 2:

document.form.button.innerHTML = new Date();


EDIT:

If what you're trying to is to make the text on the button change to the current date when you click it, this is what you want to do:

<script type="text/Javascript">
    function changeLabel()
    {
        document.getElementById('button').innerHTML = new Date();
    }
</script>

<button id="button" onclick="changeLabel()">Click Me!</button>

Solution 3:

Use innerHTML:

document.form1.button1.innerHTML=new Date();

UPDATE: Alternative you could define your button like:

<input name="button" id="button" type="button" value="Click Me!" />

In that case

document.form.button.value=new Date();

should work as you had expected .


Post a Comment for "Javascript Change Value Of Button"