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

php - trouble displaying mysqli database results in correct order -

depending on nth recurrence of job in control M -

sql server - Cannot query correctly (MSSQL - PHP - JSON) -