Solved

Delimited text to array in jscript

Posted on 2010-08-19
6
419 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 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

732 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