Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delimited text to array in jscript

Posted on 2010-08-19
6
Medium Priority
?
428 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:Gurvinder Pal Singh
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:
Gurvinder Pal Singh earned 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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:Gurvinder Pal Singh
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

927 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