0

I have a textbox which accepts date values like 01-01-2013. I need to get the year in javascript. This is the code I have used:

var oldRange, aOldRange;  
var newRange, aNewRange;  
aoldRange = new Array();  
anewRange = new Array();  
var oldYear, newYear;  
oldRange = document.getElementById(
                       '<%= txtAcademicYearStartDate.ClientID%>').value;
aOldRange = oldRange.split("-");
oldYear = aoldRange[2];

But I get the value as undefined. What's the issue?

3
  • You are using aOldRange, but refering to oldYear = aoldRange[2] Commented May 10, 2013 at 10:38
  • are u getting oldRange correctly? Commented May 10, 2013 at 10:39
  • Have solved, changed aoldRange to OldRange. Commented May 10, 2013 at 10:45

2 Answers 2

5

You have defined aOldRange, but refering to oldYear = aoldRange[2]

try

oldYear = aOldRange[2]
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, sick of me. Thanks anyway :)
2

This example is tested and working fine please refer

<script language="javascript" >         
    var oldRange, aOldRange;
    var newRange, aNewRange;
    aoldRange = new Array();
    anewRange = new Array();
    var oldYear, newYear;
    oldRange = '01-01-2013'; 
    aOldRange = oldRange.split("-"); 
    alert(aOldRange[2]);
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.