substr

You must Login before you can answer or comment on any questions.

Hey Guys, I am getting this error cannot call method substr of undefined when I try to get substring of a string. Any solutions?

6 Answers

please show some code?

see this reference http://www.w3schools.com/jsref/jsref_substring.asp

— answered 9 months ago by Aaron Saunders
answer permalink
3 Comments
  • Indeed, this is what happens why you try to run PHP functions in JAVASCRIPT

    — commented 9 months ago by Stephen Feather

  • "substr" is not exclusive to PHP, and there is a function in JS with that name also. ;)

    — commented 9 months ago by Ivan Škugor

  • I know, I was trying to pestering Aaron...

    — commented 9 months ago by Stephen Feather

Actually you are trying to call substr method on an undefined Strin variable.So Check out the value of that variable and then call substr method on that string variable.

Thanks

Either the variable is not string type or it is null.

As error message says, variable is "undefined".

if (stringVal) {
    stringVal.substr(...);
}

what is the type and value of stringVal variable? Put alert before "if" condition and check it.

— answered 9 months ago by Shalini Kushwaha
answer permalink
1 Comment
  • these are not answers.... they are comments, please place comments in the right place, it makes it easier to follow the thread

    — commented 9 months ago by Aaron Saunders

I think, pankaj and many, made right choice and answer your problem. put some code here to tell you why it is happening.

Your Answer

Think you can help? Login to answer this question!