Prepare for your Next Interview
This is a discussion on What is the problem in this code ? within the JavaScript forums, part of the Web Development category; 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= ...
|
|||
|
What is the problem in this code ?
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. -------------------- suresh |
| Sponsored Links |
|
|||
|
Re: What is the problem in this code ?
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; } Excecute the above script and it might work. |
|
|||
|
Re: What is the problem in this code ?
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...
------------------ suresh |
|
|||
|
Re: What is the problem in this code ?
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 |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Try finding the code | christia | Brainteasers | 2 | 04-09-2007 06:36 PM |
| Can you find the code | blenda | Brainteasers | 6 | 02-09-2007 06:04 AM |
| Can we modify this IL code | JobHelper | C# | 4 | 02-09-2007 06:01 AM |
| Find the code | Manojks | Brainteasers | 13 | 01-20-2007 08:53 AM |
| Find the code | sripri | Brainteasers | 4 | 09-04-2006 03:17 AM |