0

so I have a button with this event:

onmousedown="hideElements('\x22cartview\x22,\x22other\x22')"

and then this function hideElements:

function hideElements(what)
  {
  var whichElements=[what];
  alert(whichElements[0]);
  }

I want it to alert "cartview" but it alerts

"cartview","other"

I am aware of the arguments object but in this case I don't know how to use it to access the individual strings that are comma separated. Probably there is an easy solution but I am kind of new to this. Thanks!

1
  • I'm not familiar with your context, but you should probably take a look at jQuery. If you are new to web development and don't know about it, you'll be glad you did. Commented Oct 3, 2010 at 21:34

2 Answers 2

5
onmousedown="hideElements([ 'cartview', 'other' ])"

and then:

function hideElements(what) {
    alert(what[0]);
}
Sign up to request clarification or add additional context in comments.

Comments

4

It looks like the real problem is that you're passing an string, not an array. So you'd do something like:

function hideElements(/* String */ what) {
    alert(what.split(',')[0]);
}

or with an array:

function hideElements(/* Array<String> */ what) {
    alert(what[0]);
}

or passing multiple strings directly into the function:

function hideElements(/* String */ what) {
    alert(arguments[0]);
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.