Simple Javascript problem

I'm NOT a javascripter;  this should be easy -- but it aint working!

var wireless_no = $( "input[name=wireless_no]" ).val().trim() ;
  alert(wireless_no) ;
  wireless_no = wireless_no.strip_phone_format() ;

Open in new window

And my function:
// *************************************************************************************************

String.prototype.strip_phone_format = function (phone_no)
{
  var phone=phone_no.toString() ;    // just in case.  Chrome inspector says phone_no above is undefined.
  var front=phone.replace("(","") ;
  var middle=phone.replace(") ","") ;
  var back=phone.replace("-","") ;
  
  return front+middle+back ;
} ;

Open in new window


The alert shows the 4 digits I type.
The functions insists that phone_no is undefined.

What am I missing?

Thank you.
RalphAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaauCommented:
You function does not expect any parameters, as a result you should work with "this":
// *************************************************************************************************

String.prototype.strip_phone_format = function ()
{
  var phone=this.toString() ;    // just in case.  Chrome inspector says phone_no above is undefined.
  var front=phone.replace("(","") ;
  var middle=phone.replace(") ","") ;
  var back=phone.replace("-","") ;
  
  return front+middle+back ;
} ;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zzynxSr. Software engineerCommented:
You defined your function with a parameter, but when you call it, you don't pass it:

wireless_no = wireless_no.strip_phone_format() ;

Open in new window


I would define the function simply as

strip_phone_format : function (phone_no)  {
  var phone=phone_no.toString() ;
  var front=phone.replace("(","") ;
  var middle=phone.replace(") ","") ;
  var back=phone.replace("-","") ;
  return front+middle+back ;
} ;

Open in new window


and then use it like this:

var wireless_no = $( "input[name=wireless_no]" ).val().trim() ;
alert(wireless_no) ;
wireless_no = strip_phone_format(wireless_no) ;

Open in new window

RalphAuthor Commented:
Dumb mistake on my part.  Thank you.
Also the code needed fixing, but that was easily done.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.