Salah a a a Al Jasem
asked on
Java script comparing two variables
There must be some thing there - the following two issues must be related to one reason, I spend two days to understand why
ISSUE 1
var y2 = 2000;
alert(y2); (this line gives alert 2000 which means y2 value is 2000)
alert(y2 == 2000); (this line gives alert true which also means y2 value is 2000)
if (y2 = 2000 ) {
alert("y2 is equals 2000"); (never get to this alers !!!!! any Idea?)
return false;
}
ISSUE 2
assuming textbox1.text="11-1-2000"
assuming textbox2.text="11-1-2001"
var T1= document.getElementById("< %=Textbox1 .ClientID% >");
var year1 = T1.value.split("-")[2];
var T2= document.getElementById("< %=Textbox2 .ClientID% >");
var year2 = T2.value.split("-")[2];
alert(year1); (this line gives alert 2000 which means T1 value is 2000)
alert(year2); (this line gives alert 2001 which means T2 value is 2001)
if (year1 > Year2)
{
Alert("Year1 is GT Year2") (never get to this alers !!!!! any Idea?)
return false;
}
ISSUE 1
var y2 = 2000;
alert(y2); (this line gives alert 2000 which means y2 value is 2000)
alert(y2 == 2000); (this line gives alert true which also means y2 value is 2000)
if (y2 = 2000 ) {
alert("y2 is equals 2000"); (never get to this alers !!!!! any Idea?)
return false;
}
ISSUE 2
assuming textbox1.text="11-1-2000"
assuming textbox2.text="11-1-2001"
var T1= document.getElementById("<
var year1 = T1.value.split("-")[2];
var T2= document.getElementById("<
var year2 = T2.value.split("-")[2];
alert(year1); (this line gives alert 2000 which means T1 value is 2000)
alert(year2); (this line gives alert 2001 which means T2 value is 2001)
if (year1 > Year2)
{
Alert("Year1 is GT Year2") (never get to this alers !!!!! any Idea?)
return false;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many many thanks for you guys for trying to help
Mr Krakatoa
if you mean (Year2) not same as (year2) because variables are case sensitive, then one can use several variables with on name!!! (strange idea)
e.g.
Year2
YEar2
YeAr2
YeaR2
......
I did not know that, this will make me check all other codes :( thank you for waking me up
Mr Jim
you are right in my original code year1 is 2001 and Year2 is 2000 spelling mistake
Mr HainKurt
I am looking into you code
Mr Krakatoa
if you mean (Year2) not same as (year2) because variables are case sensitive, then one can use several variables with on name!!! (strange idea)
e.g.
Year2
YEar2
YeAr2
YeaR2
......
I did not know that, this will make me check all other codes :( thank you for waking me up
Mr Jim
you are right in my original code year1 is 2001 and Year2 is 2000 spelling mistake
Mr HainKurt
I am looking into you code
ASKER
The main issue is that the variables in javascript is case sensitive
it took many days from me to realize that
Mr Krakatoa reply figure out the exact point
Thanks to all of you
it took many days from me to realize that
Mr Krakatoa reply figure out the exact point
Thanks to all of you
You use "==" to compare values in Java , not "=".