Unable to get value of the property 'split': object is null or undefined

Newbie to HTML here. Using IE9, I'm getting the Error on Page Unable to get value of the property 'split': object is null or undefined. The selected code section is

var     retDate = null
var     oscriptDateString = form._1_1_56_1.value
if ( oscriptDateString != '?' )
{
var     temp = oscriptDateString.split( '/' )
var     temp2 = temp[ 3 ].split( ':' )  //Getting Error Here
var     yearX = parseInt( temp[ 1 ] )
var     monthX = parseInt( temp[ 2 ] ) - 1
var     dayX = parseInt( temp2[ 0 ] )
var     hourX = parseInt( temp2[ 1 ] )
var     minuteX = parseInt( temp2[ 2 ] )
var     secondX = parseInt( temp2[ 3 ] )
retDate = new Date( yearX, monthX, dayX, hourX, minuteX, secondX )
}
return retDate

It only returns this error when the field is blank. Otherwise works fine. Am I missing something?

Answers


You are reading from a field called _1_1_56_1

var     oscriptDateString = form._1_1_56_1.value

You then split this field, and name the result temp

var     temp = oscriptDateString.split( '/' )

If your temp is empty/null/undefined, because the above assignment failed (because the field was empty or it contained no slash...

temp[ 3 ].split( ':' )

Then temp here will be undefined. You can't call the fourth element (third position) of nothing.


Need Your Help

require.js text plugin adds ".js" to the file name

javascript text backbone.js requirejs

I'm trying to work with requirejs and text plugin and I have weird problem.