Geeks Talk

Prepare for your Next Interview




What is the problem in this code ?

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= ...


Go Back   Geeks Talk > Web Development > JavaScript

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-04-2007
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,007
Thanks: 0
Thanked 73 Times in 62 Posts
psuresh1982 will become famous soon enough
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
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-04-2007
Junior Member
 
Join Date: Mar 2007
Location: Bangalore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sugunav is on a distinguished road
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.
Reply With Quote
  #3 (permalink)  
Old 04-30-2008
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,007
Thanks: 0
Thanked 73 Times in 62 Posts
psuresh1982 will become famous soon enough
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
Reply With Quote
  #4 (permalink)  
Old 06-16-2008
Expert Member
 
Join Date: Dec 2007
Location: Pune
Posts: 128
Thanks: 0
Thanked 6 Times in 6 Posts
peeyush_jain is on a distinguished road
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
Reply With Quote
Reply

  Geeks Talk > Web Development > JavaScript


Thread Tools
Display Modes


Similar Threads

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


All times are GMT -4. The time now is 04:18 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved