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.

basic if statement dow not work

buzzersdad

New member
Joined
Dec 15, 2021
Messages
5
Reaction score
0
HTML Coins
0
This works as shown, but if you include the "if" statement, it doesn't work. (I'm new at this, and have searched everywhere I know of to find what's wrong - it must be simple)

<!DOCTYPE html>
<html>
<body>
<style>
.box { width: 80px; height: 80px; margin: 0px; padding:0px; border: 1px solid black; position: absolute; }
</style>
<script>
function swap(id) {
var a=document.getElementById(id).getAttribute("value")
// if a == "x" {
document.write(a);
// }
}
</script>
<div class="box" onclick="swap('00')" id="00" value="x"
</div>
</body>
</html>
 
<div class="box" onclick="swap('00')" id="00" value="x"

I'm sure you've solved it by now, but you forgot the > on the other side of the div class
 
Could you help us with what you’re trying to achieve? Maybe there’s a better alternative?
 
What I was trying to achieve was more complicated, I just reduced the code bit by bit to the smallest number of statements to isolate where my code was failing. It started as an attempt to set up a toggle switch (using the "value" fiield as a 1 or a 0) to change a background image back and forth by clicking on its container. This required the "if" statement to determine if the value was a 1 or a 0.
 
What I was trying to achieve was more complicated, I just reduced the code bit by bit to the smallest number of statements to isolate where my code was failing. It started as an attempt to set up a toggle switch (using the "value" fiield as a 1 or a 0) to change a background image back and forth by clicking on its container. This required the "if" statement to determine if the value was a 1 or a 0.
Use a Boolean for the value. Booleans are either True or False. Where as integers can be many different options.
 
The problem then becomes how to represent a boolean value in the HTML value="...." statement.
 

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