This is the javascript. Here "FY" and "TY" are the 'id' for a select-box which has years listed in it.
function checkYear()
{
var y1= document.getElementById("FY");
var y2= document.getElementById("TY");
x1=y1.options[y1.selectedIndex].value;
x2=y2.options[y2.selectedIndex].value;
if(x2 < x1)
{
alert("'From' year should be less than or equal to 'To' year");
return false;
}
else
return true;
}
In that above function is not working. Whenever i run this function it display nothing. Actually the "if" condition is true then i am going to display one message using alert. But it is not displaying. What is the problem in this function ? Plaease Clarify with this. If i got the answer, i will post here.
In your javascript,you have already stored the year values in y1 and y2.Then y do u need to assign them to x1 and x2?? Exclude x1 and x2 assignment statements and change the if condition to compare y1 and y2.The modified code has been given below.
function checkYear()
{
var y1= document.getElementById("FY");
var y2= document.getElementById("TY");
/*x1=y1.options[y1.selectedIndex].value;
x2=y2.options[y2.selectedIndex].value; */
if(y1 >y2)
{
alert("'From' year should be less than or equal to 'To' year");
return false;
}
else
return true;
}
I think it is coming like a string values. So we need to convert it into integer values. I convert that into integer values after that it is working fine...
HI friend , might be you problem is on
x1=y1.options[y1.selectedIndex].value;
x2=y2.options[y2.selectedIndex].value;
statment please try to to replace both statment to
x1=parseInt(y1.options[y1.selectedIndex].value);
x2=parseOnt(y2.options[y2.selectedIndex].value);
Please let me know if you still facing problem