0

button1Toggle() function doesn't seem to work. Text in the button doesn't change. Can't find the bug.

 function button1Toggle() {
    if (document.myform.button1.value == "Mute") {
         document.myform.button1.value = "Unmute";
      } else {
         document.myform.button1.value = "Mute";
      }
    }
<div>Tablet</div><br>
<form name ="myform">
    <input type="button" name="button1" id="button1" value="Mute" onclick="button1Toggle()">
</form>

4
  • write: document.getElementById('button1').value Commented Nov 2, 2014 at 6:00
  • you code seems fine.. probably your code have another bug Commented Nov 2, 2014 at 6:02
  • Your code is works, or maybe some browser issues? Commented Nov 2, 2014 at 6:07
  • Maybe you have another button with the same id? Commented Nov 2, 2014 at 6:14

1 Answer 1

1

Maybe you have another button with the same id?

Try -

function button1Toggle(btn) {
    if (btn.value == "Mute") {
        btn.value = "Unmute";
    } else {
        btn.value = "Mute";
    }
}


 <div>Tablet</div><br>
     <form name ="myform">
        <input type="button" name="button1" id="button1" value="Mute" onclick="button1Toggle(this)">
    </form>
Sign up to request clarification or add additional context in comments.

1 Comment

or more concisely: button1Toggle(btn) { btn.value = (btn.value === "mute")? "unmute" : "mute"; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.