2

I have to change the text of several buttons to whatever I type into a 'textbox'. When I click the first button, the text from the textbox should become the text of the button. The HTML code:

          <input id="textbox" type="text" size="30" />
          <br/>
          <button id="b1">Button 1</button>
          <br/>
          <button id="b2">Button 2</button>
          <br/>
          <button id="b3">Button 3</button>
          <br/>
          <button id="b4">Button 4</button>
          <br/>
          <button id="b5">Button 5</button>
          <br/>

I know how to create alerts in javascript using functions and

          document.getElementById("b1").onclick = click;

but how do I make the button of the text change? What command can I use inside an if statement instead of alert which would replace the text of the button with the text inside the textbox? I have looked all over but can't find the answer. Any help is appreciated :)

1 Answer 1

3

You can change the button text like:

if(condition) {
    document.getElementById("b1").innerHTML = document.getElementById("textbox").value;
}
Sign up to request clarification or add additional context in comments.

Comments

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.