Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

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= document.getElementById("TY"); x1=y1.options[y1.selectedIndex].value; ...

Go Back   Geeks Talk > Web Development > JavaScript
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 04-04-2007
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,016
Thanks: 0
Thanked 91 Times in 72 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,016
Thanks: 0
Thanked 91 Times in 72 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: 139
Thanks: 0
Thanked 7 Times in 7 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
  #5 (permalink)  
Old 04-25-2009
Junior Member
 
Join Date: Apr 2009
Location: chennai
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
nagasen is on a distinguished road
Re: What is the problem in this code ?

insted of that ...
get combo name and check the year.. like this






function fun(){
if(document.frm.ch.value>document.frmch1.value)
alert()
else
alert()
}
Reply With Quote
Reply

  Geeks Talk > Web Development > JavaScript

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Try finding the code christia Brainteasers 2 04-09-2007 07:36 PM
Can you find the code blenda Brainteasers 6 02-09-2007 07:04 AM
Can we modify this IL code JobHelper C# 4 02-09-2007 07:01 AM
Find the code Manojks Brainteasers 13 01-20-2007 09:53 AM
Find the code sripri Brainteasers 4 09-04-2006 04:17 AM


All times are GMT -4. The time now is 08:21 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved