views:

52

answers:

2

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!

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

and then:

function hideElements(what) {
    alert(what[0]);
}
Darin Dimitrov
+3  A: 

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]);
}
jay
That makes sense thanks for explaining.
Troy