Results 1 to 5 of 5

Thread: What is the problem in this code ?

  1. #1
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    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


  2. #2
    Junior Member
    Join Date
    Mar 2007
    Answers
    1

    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.


  3. #3
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    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


  4. #4
    Expert Member
    Join Date
    Dec 2007
    Answers
    138

    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


  5. #5
    Junior Member
    Join Date
    Apr 2009
    Answers
    4

    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()
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact