howardjennings Posted March 4, 2016 Share Posted March 4, 2016 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 More sharing options...
Ingolme Posted March 4, 2016 Share Posted March 4, 2016 You need to use the comparison operator "==" in your if() statements rather than the assignment operator "=". if (Prop_Type == 1) { Link to comment Share on other sites More sharing options...
howardjennings Posted March 4, 2016 Author Share Posted March 4, 2016 thanks it works now. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now