简体   繁体   中英

Get textbox text in Javascript

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?

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

try

oldYear = aOldRange[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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM