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!

share|improve this question
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. – Jim Garvin Oct 3 '10 at 21:34
feedback

2 Answers

up vote 5 down vote accepted
onmousedown="hideElements([ 'cartview', 'other' ])"

and then:

function hideElements(what) {
    alert(what[0]);
}
share|improve this answer
feedback

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]);
}
share|improve this answer
That makes sense thanks for explaining. – Troy Oct 3 '10 at 21:28
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.