Solved

Delimited text to array in jscript

Posted on 2010-08-19
6
421 Views
Last Modified: 2013-11-19
hi,

i have this function definition:
 
function xtoggleDisplay(aid, atagname, aclassname, adisplayvalue) {
  var obj = document.getElementById(aid);
  var elements = obj.getElementsByTagName(atagname);
  for (var i = 0; i < elements.length; i++) {
	if ((aclassname == '') || (elements[i].className == aclassname)) elements[i].style.display = adisplayvalue;
  }
}
function xtoggleOn(aid, atagname, aclassname) {
  xtoggleDisplay(aid, atagname, aclassname, '');
}
function xtoggleOff(aid, atagname, aclassname) {
  xtoggleDisplay(aid, atagname, aclassname, 'none');
}

Open in new window


i have this onclick event:
 
onclick="xtoggleOff('tbl_data_1', 'tbody', ''); xtoggleOff('tbl_data_1', 'tr', '');"

Open in new window


i'd like to able to set the onclick like this:
 
xtoggleOff('tbl_data_1', 'tbody;tr', '');

Open in new window


it's like creating a array from a delimited string
how can i do that ?
0
Comment
Question by:Geert Gruwez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33475195
<<it's like creating a array from a delimited string
how can i do that ?>>
pardon my ignorance, but didn't quite get the meaning of this, could you please rephrase?
Also please mention what is the problem that you are facing.
Thanks
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 33475304
it's in the small print ...

now i call a procedure xtoggleOff twice for 2 different tagName's (tbody and tr)

i'd like to be able to call xtoggleOff only once, but pass it both tagName's in 1 string
using a delimited string

the code xtoggleDisplay would have to change for this to work:

function xtoggleDisplay(aid, atagname, aclassname, adisplayvalue) {
  var obj = document.getElementById(aid);
  var elements = obj.getElementsByTagName(atagname);

this is the problem i can't solve:
var classnames = stringtoarray(aclassname);

change to something like below
function xtoggleDisplay(aid, atagname, aclassname, adisplayvalue) {
  var obj = document.getElementById(aid);
>>  var classnames = stringtoarray(aclassname);
  var elements = obj.getElementsByTagName(atagname);

function xtoggleDisplay(aid, atagname, aclassname, adisplayvalue) {
  var obj = document.getElementById(aid);
>>  var classnames = stringtoarray(aclassname);
  var elements = obj.getElementsByTagName(atagname);
  for (var i = 0; i < elements.length; i++) {
    x = 0;
    if (aclassname == '') x=1;
>>    for (var j=0; j < classnames.length; j++) {
>>      if (elements[i].className == classnames[j]) x=1;
>>    }
    if (x == 1) elements[i].style.display = adisplayvalue;
  }

Open in new window

0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 33475336
you can easily pass the comma separated string and then convert it into an array using
split method String
http://www.w3schools.com/jsref/jsref_split.asp

Let me know if this helps
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 38

Author Comment

by:Geert Gruwez
ID: 33475355
exactly what i was looking for !

and a reference to the basics of JScript also.
Now i can really dig in.

Thanx
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33475379
thanks for the points :)
0
 
LVL 38

Author Comment

by:Geert Gruwez
ID: 33475447
sometimes i wonder why i look for things myself
and not ask a question straight away in the appropriate TA

I spent more than an hour trying to find a JScript reference on MSDN library.
I could have had it in 10 minutes as this Q proves again.

Thanx for the fast response.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question