Toggling button inner HTML with if statement not working


(Greg) #1

So I can change the button inner html with this code and it works fine.

hypeDocument.getElementById('button').innerHTML = 'Reset';

However, when I put this code into an if statement to make the button toggle between ‘Submit’ and ‘Reset’ upon click it doesn’t work:

if (hypeDocument.getElementById('button').innerHTML = 'Submit') {
	hypeDocument.getElementById('button').innerHTML = 'Reset';
	
} else {

  	hypeDocument.getElementById('button').innerHTML = 'Submit';

What am I doing wrong?

Thanks for your help!


(Mark Hunte) #2

First I assume that the missing bracket to close off the else is a copy and paste typo.

A single equals sign “=” is an Assignment Operator to set a value.
( set value on the left side of the = to the value on the right side of the = sign )

A double equals sign “==” is a Comparison Operator of is equal to

( check if the value from the left side of the == signs is equal to the right side of the == signs,
return true/false )

Can you now spot where you have gone wrong.


(Greg) #3

Thanks MarkHunte for this brief educational experience. I’m glad you gave me a clue to figure it out instead of telling me. I’m a js idiot :laughing::laughing::laughing:

Works like a charm!

Btw, what does “===” (tripple equals sign) mean then?


(Mark Hunte) #4

It means equal value and equal type.

Check out operators