my function below keeps breaking at var pos1=dtStr.indexOf(dtch)
function isDate(dtStr){
var daysInMonth = DaysArray(12);
var pos1 = dtStr.indexOf(dtCh);
var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
var strMonth = dtStr.substring(0, pos1);
var strDay = dtStr.substring(pos1 + 1, pos2);
var strYear = dtStr.substring(pos2 + 1);
strYr = strYear;
the error message that I am getting is SCRIPT438: Object doesn't support property or method 'indexOf'. I took out all of my code after the variables and I am still receiving the same error
my function below keeps breaking at var pos1=dtStr.indexOf(dtch)
function isDate(dtStr){
var daysInMonth = DaysArray(12);
var pos1 = dtStr.indexOf(dtCh);
var pos2 = dtStr.indexOf(dtCh, pos1 + 1);
var strMonth = dtStr.substring(0, pos1);
var strDay = dtStr.substring(pos1 + 1, pos2);
var strYear = dtStr.substring(pos2 + 1);
strYr = strYear;
the error message that I am getting is SCRIPT438: Object doesn't support property or method 'indexOf'. I took out all of my code after the variables and I am still receiving the same error
isDate
?
– Alex Turpin
Commented
Nov 16, 2011 at 21:46
this
? You understand that indexOf
is a function for strings? What exactly are you trying to achieve?
– Alex Turpin
Commented
Nov 16, 2011 at 21:53
onkeyup
, that means this
is the HTML element, you need to use .value
to get its value.
– gen_Eric
Commented
Nov 16, 2011 at 22:06
this
is the input object. You need to use it's value instead. See @Rocket's answer.
– Alex Turpin
Commented
Nov 16, 2011 at 22:07
The isDate
function is expecting its dtStr
parameter to be a String
(as indicated by the indexOf
and substring
function calls). However, the function is being invoked with an argument that is of type Object
rather than String
. You will need to modify the code where this function is being called to pass the correct parameter to the isDate
function.
You said you're doing onkeyup="isDate(this);"
. This is passing the element to isDate
, you need to get its value before you can use it.
function isDate(dtStr){
dtStr = dtStr.value;
// ...
}