javascript - What is wrong with ".replace"? -


can please me understand wrong simple function?

function generatesku(inputfield) {     return inputfield.replace(" ","."); } 

typeerror: cannot call method "replace" of undefined.

i tried inputfield.value.replace() .. produced same error.. inputfield.tostring.replace().. gives me exact same error..

no matter do, cannot apply string function on this. there nothing else in script. function. first script ever.

also, if return inputfield, returns fine , replaces value.

i using function calling inside cell like

=generatesku(a1) 

like that.

if can i'll obliged.

the function being called without parameter (or being passed resolves undefined or null). empty cells perhaps? if you're not controlling invocation, you'll need guard it:

function generatesku(inputfield) {     if (inputfield) {         return inputfield.replace(" ",".");     } } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -