I have this weird problem:
Below is a JavaScript function
function calculateSum()
{
var e2 = document.getElementById('hotel_names');
var selValue2 = e2.options[e2.selectedIndex].value;
if (selValue2='1')
{
alert("helloworld");
}
else
{
alert("byeworld");
}
//function closes
}
It captures the option value of an HTML element selection and show the appropriate message…or it should be. The thing is it always shows 1 no matter the selection.
On the other hand the following works.
function calculateSum()
{
var e2 = document.getElementById('hotel_names');
var selValue2 = e2.options[e2.selectedIndex].value;
alert(selValue2);
}
The second function shows the correct number each time you select an option from the selection.
Any ideas why the first one does not work?
Conditional statements use double equals sign called an equality operator –
By using only one what you are essentially doing is assigning a value to the variable. This is called an assignment operator.