Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What I mean is for example if a variable starts as No and if you pressed a button how would I get it to change to yes. I also want it to show the variable .

What I have tried:

Tbh, I have no idea where to start with this.
Posted
Updated 29-Mar-21 10:03am

This is very basic JavaScript so I would suggest reading some books and doing online learning to learn the basics. This should get you started

This is a button that when clicked will call a function named buttonClick.
HTML
<button onclick="buttonClick();">Click me.</button>


buttonClick function will change the variable value and then display it.
JavaScript
var myVariable = "No";

function buttonClick(){
  myVariable = "Yes";
  alert(myVariable);
}
 
Share this answer
 
Try this:
1) Open up your Web Browser dev console (F12 in most browsers)
2) copy the code below
3) paste it into the console window and hit <enter>
4) a button will appear on this page right below your member name (where you posted the question).
5) click the button and it will display the message "test this"

JavaScript
var x = document.createElement("button");
x.innerHTML="click me";
document.querySelector(".member-rep-container").appendChild(x); 
x.addEventListener("click", () => alert("test this!"));


Now that is hands-on learning. 😁😁
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900