Solved

Delimited text to array in jscript

Posted on 2010-08-19
6
412 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
  • 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 36

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 36

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 36

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now