0

I have the following function call

    setVal("' + key + ',' + addressid + '")

Note how I am trying to pass in 2 values, key and address id.

I have the actual function as below:

    function setVal(key, addressid) {

    }

when I check the value of key in the SetVal function, I get key = the value of hcpkey + ',' + addressid.

The value of addressid is undefined although it does have a value. Am I doing something wronge in how I am passing the value?

2
  • 1
    Why on earth would you write that? Commented May 7, 2012 at 15:33
  • You're passing in only 1 parameter, a string delimited by your double-quotes. Commented May 7, 2012 at 15:34

7 Answers 7

2

Get rid of all those quotes.

Sign up to request clarification or add additional context in comments.

Comments

1

You call the function with one big string: "' + key + ',' + addressid + '")

You should call it like this:

setVal("First Value", "Second Value");

If those are variables, leave the quotes:

setVal(key, addressid);

Comments

1

You are passing a single argument; a string with the value ' + key + ',' + addressid + '

Unless you're trying to do something I've not picked up on, you just want this:

setVal(key, addressid)

Comments

0

You should simply call your function like this:

setVal(key, addressid);

Comments

0

Do not use quotes where you don't need them:

setVal(key, addressid);

You want variables (or rather their values) and not the variable names.

Comments

0

yes, you need to pass them separately:

setVal(key, addressid);

Comments

0

Call the function like this:

setVal(key, addressid);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.