Solved

Delimited text to array in jscript

Posted on 2010-08-19
6
417 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 37

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 37

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 37

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Browser Chrome downloads colored link 5 41
Scroll 5 news at a time. 4 28
Can't get container centered 4 16
How to reload page and grab querystring 2 11
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 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