admin管理员组文章数量:1026373
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
Share Improve this question edited Nov 16, 2011 at 21:48 mu is too short 435k71 gold badges859 silver badges818 bronze badges asked Nov 16, 2011 at 21:43 Juan AlmonteJuan Almonte 3952 gold badges8 silver badges14 bronze badges 5-
2
What are you passing
isDate
? – Alex Turpin Commented Nov 16, 2011 at 21:46 -
2
And what is
this
? You understand thatindexOf
is a function for strings? What exactly are you trying to achieve? – Alex Turpin Commented Nov 16, 2011 at 21:53 - I am trying to get the date entered into a textfield and break it into substrings at the dtCh either "-" or "/" – Juan Almonte Commented Nov 16, 2011 at 22:02
-
@Juan: Since you're using
onkeyup
, that meansthis
is the HTML element, you need to use.value
to get its value. – gen_Eric Commented Nov 16, 2011 at 22:06 -
1
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
2 Answers
Reset to default 2The 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;
// ...
}
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
Share Improve this question edited Nov 16, 2011 at 21:48 mu is too short 435k71 gold badges859 silver badges818 bronze badges asked Nov 16, 2011 at 21:43 Juan AlmonteJuan Almonte 3952 gold badges8 silver badges14 bronze badges 5-
2
What are you passing
isDate
? – Alex Turpin Commented Nov 16, 2011 at 21:46 -
2
And what is
this
? You understand thatindexOf
is a function for strings? What exactly are you trying to achieve? – Alex Turpin Commented Nov 16, 2011 at 21:53 - I am trying to get the date entered into a textfield and break it into substrings at the dtCh either "-" or "/" – Juan Almonte Commented Nov 16, 2011 at 22:02
-
@Juan: Since you're using
onkeyup
, that meansthis
is the HTML element, you need to use.value
to get its value. – gen_Eric Commented Nov 16, 2011 at 22:06 -
1
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
2 Answers
Reset to default 2The 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;
// ...
}
本文标签: javascriptSCRIPT438 Object doesn39t support property or method 39indexOf39Stack Overflow
版权声明:本文标题:javascript - SCRIPT438: Object doesn't support property or method 'indexOf' - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745642994a2160858.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论