What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

on click button not working. Could you please help me in identifying the bug

Kiriti

New member
Joined
Nov 19, 2022
Messages
1
Reaction score
0
HTML Coins
0
<!DOCTYPE html>
<html>
<head>
<title>program 1a</title>
</head>
<body style="background-color:green">
<h2>when you click on press me it will change text</h2>
<p id="Demo">Gokaraju</p>
<button onclick="Change text()">click me
</button>
<script>
function "Change text()"
{
if(document.getElementById("Demo").innerHTML="Gokaraju");
{
document.getElementById("Demo").innerHTML="2nd CSE A");
}
else
{
document.getElementById("Demo").innerHTML="Siva";
}
}
</script>
</body>
</html>
 
Change text() is a method. Syntax is wrong. Use or name it properly. myFunction() or changeText() which ever suits you. Into your coding.

<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World"; //or something else. Add your own words. It is not a conditional statement.
}
</script>
What I mean?
 
What you wanted was 3 choices. Gokaraju, 2nd CSE A, and Siva when pressed three times. Then you need to write it differently. Value returns to the original text or null because a space in memory is being used. The next option. 2nd CSE A. Now it's conditional. Try this in your script.

Code:
// declaring a value
//like that

let i = 0;
let text = " "; //add the names here.  2nd name.  ,  ... and so on.
for (; i < text; i++) { 
  text += text;
} //end for loop

Bottom is another writing.  You can write it any variations.

x[1]=" "
x[2]=" "
x[3]=" "

for (let i = 0; i < x;  i++) { 
   i;
} //end loop

So for 4 values of i. 1 for null. So the program repeats itself. Pressing it three times.
 
Last edited:
Here is the final code
Code:
<body>
<p id="Demo">
<button onclick="changeText()"> click me </button>
<script>
function changeText();
let i=0;
let text=" Gokaraju" , " 2nd CSE A ", " Siva";
for( i; i < text ; i++)  {
text += text;
} //end loop
document.getElementByid("Demo").innerHTML(text);
</script>
</p>
</body>

Press it 3 times for all names

output is:

Gokaraju
2nd CSE A
Siva
 
Last edited:

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back