Jump to content

IF ELSE not working


howardjennings
 Share

Recommended Posts

Hi

I'm trying to create some java script to do some calculations on a Caldera Form. I've taken an example from one of the tutorials on this site and change a couple of the variables and now it doesn't work. Can anyone point out my mistake?

 

I've copied the entire stuff from the example, this is my version, I've changed the 'TIME' var to 'Prop_Type' and removed the calculation and replaced it with a number. the original is at the bottom of this post.

 

 

 

<!DOCTYPE html>
<html>
<body>
<p>Click the button to get a time-based greeting:</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var greeting;
var Prop_Type = 2;
if (Prop_Type = 1) {
greeting = "Apartment";
} else if (Prop_Type = 2) {
greeting = "Commercial";
} else {
greeting = "Residential";
}
document.getElementById("demo").innerHTML = greeting;
}
</script>
</body>
</html>
ORIGINAL code
<!DOCTYPE html>
<html>
<body>
<p>Click the button to get a time-based greeting:</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var greeting;
var time = new Date().getHours();
if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
document.getElementById("demo").innerHTML = greeting;
}
</script>
</body>
</html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...