Avatar of Ralph
Flag for United States of America

asked on 

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.

Avatar of undefined
Last Comment

8/22/2022 - Mon