variablen zusammenfassen

M

max

ich finde nicht heraus, wie ich drei variablen zu einer zusammenfassen
kann:
3 existierende variablen:
var aa = "einseins";
var ab = "einszwei";
var ac = "einsdrei";
ich möchte die 3 zusammenfassen:
var a3 = aa + ab + ac ; oder
var a3 = (aa,ab,ac) ; oder wie??

vielen dank, max.
 
V

VK

max said:
ich finde nicht heraus, wie ich drei variablen zu einer zusammenfassen
kann:
3 existierende variablen:
var aa = "einseins";
var ab = "einszwei";
var ac = "einsdrei";
ich möchte die 3 zusammenfassen:
var a3 = aa + ab + ac ; oder
var a3 = (aa,ab,ac) ; oder wie??

var a3 = aa + ab + ac ;

or (for strings concatenation):

var a3 = aa.concat(ab, ac);
 
E

Evertjan.

VK wrote on 31 okt 2006 in comp.lang.javascript:

Did you try, Max?

Did you try, Max?
var a3 = aa + ab + ac ;

or (for strings concatenation):

var a3 = aa.concat(ab, ac);

Correct,
depending of what is ment by "Variablen zusammenfassen":

<http://dict.leo.org/ende?search=zusammenfassen>
<http://dict.leo.org/ende?search=concatenate>
<http://dict.leo.org/ende?search=addieren>

=========

Perhaps you like this better:

var aa = "einseins";
var ab = "einszwei";
var ac = "einsdrei";
var a3 = [aa,ab,ac].join(' ');

Eins?
 
M

max

I don't get it working. here my layout:
var aa = "einseins"; var ab = "einszwei"; var ac = "einsdrei";
var a3 = aa + ab + ac ; // this should sum up the 3 vars above
function showEins() {
for (i = 0; i <=0; i++)
{
// show1 = [aa, ab, ac]; // with i<=2; this works, but is too long in
other cases
show1 = [a3]; // does not work
// var a3 = [aa,ab,ac].join(' '); // did not work either. do I have
to fill in the brackets?
document.getElementById(show1).style.visibility ="visible";
}
}

thank you. max.


Evertjan. said:
VK wrote on 31 okt 2006 in comp.lang.javascript:

Did you try, Max?

Did you try, Max?
var a3 = aa + ab + ac ;

or (for strings concatenation):

var a3 = aa.concat(ab, ac);

Correct,
depending of what is ment by "Variablen zusammenfassen":

<http://dict.leo.org/ende?search=zusammenfassen>
<http://dict.leo.org/ende?search=concatenate>
<http://dict.leo.org/ende?search=addieren>

=========

Perhaps you like this better:

var aa = "einseins";
var ab = "einszwei";
var ac = "einsdrei";
var a3 = [aa,ab,ac].join(' ');

Eins?
 
O

Otto Lang

Please do not place your text on top of the quoted text.

max said:
I don't get it working. here my layout:
var aa = "einseins"; var ab = "einszwei"; var ac = "einsdrei";

Okay, you have 3 variables. Each is a string.
var a3 = aa + ab + ac ; // this should sum up the 3 vars above

This results in

a3 = "einseinseinszweieinsdrei";
function showEins() {
for (i = 0; i <=0; i++)

This doesn't make any sense. After the first run this loop will stop
because ``i'' is greater than zero after ``i++''.
{
// show1 = [aa, ab, ac]; // with i<=2; this works, but is too long in
other cases

Here you create an array with 3 items: ``einseins'', ``einszwei'' and
``einsdrei''.
show1 = [a3]; // does not work

To read the 3rd item of this array you have to write

show1[2]

Arrays are zero based. With your syntax you create an array ``show1''
with 1 item.
// var a3 = [aa,ab,ac].join(' '); // did not work either. do I have
to fill in the brackets?

This results in

a3 = "einseins einszwei einsdrei"
document.getElementById(show1).style.visibility ="visible";


What do you exactly want to do?
thank you. max.

HTH
../otto
 
M

max

Otto said:
Please do not place your text on top of the quoted text.

max said:
I don't get it working. here my layout:
var aa = "einseins"; var ab = "einszwei"; var ac = "einsdrei";

Okay, you have 3 variables. Each is a string.
var a3 = aa + ab + ac ; // this should sum up the 3 vars above

This results in

a3 = "einseinseinszweieinsdrei";
function showEins() {
for (i = 0; i <=0; i++)

This doesn't make any sense. After the first run this loop will stop
because ``i'' is greater than zero after ``i++''.
{
// show1 = [aa, ab, ac]; // with i<=2; this works, but is too long in
other cases

Here you create an array with 3 items: ``einseins'', ``einszwei'' and
``einsdrei''.
show1 = [a3]; // does not work

To read the 3rd item of this array you have to write

show1[2]

Arrays are zero based. With your syntax you create an array ``show1''
with 1 item.
// var a3 = [aa,ab,ac].join(' '); // did not work either. do I have
to fill in the brackets?

This results in

a3 = "einseins einszwei einsdrei"
document.getElementById(show1).style.visibility ="visible";


What do you exactly want to do?
thank you. max.

HTH
./otto
--
/"\ ASCII ribbon | http://www.wean.at
\ / campaign against | http://www.lang-kritz.at
x HTML postings | http://www.diepranger.at
/ \ & email |


thanks for your detailed commentary.
what I need to do is simplifying a dynamic navigation for a website.
the navigation has three hierarchic levels. with each mouse rollover
some field show, others hide. this is defined in js as follows:
----------------------------------
function showEinszwei() {
for (i = 0; i <=7; i++)
{
show1 = ["einseins", "einszwei", "einsdrei",
"einsvier","einszweieins", "einszweizwei", "einszweidrei",
"einszweivier"];
document.getElementById(show1).style.visibility ="visible";
}
for (i = 0; i <=71; i++)
{
hide1 =
["einseinseins","einseinszwei","einseinsdrei","einsdreifuenf",
"einsdreieins", "einsdreizwei", "einsdreidrei", "einsdreivier",
"einsviereins", "einsvierzwei", "einsvierdrei", "einsviervier",
"zweieins", "zweizwei", "zweidrei", "zweivier",
"zweieinseins","zweieinszwei","zweieinsdrei","zweieinsvier","zweizweieins","zweizweizwei",
"zweizweidrei","zweizweivier","zweidreieins","zweidreizwei","zweidreidrei","zweidreivier",
"zweiviereins","zweivierzwei","zweivierdrei","zweiviervier","dreieins","dreizwei","dreidrei",
"dreivier","dreieinseins","dreieinszwei","dreieinsdrei","dreieinsvier","dreizweieins","dreizweizwei",
"dreizweidrei","dreizweivier","dreidreieins","dreidreizwei","dreidreidrei","dreidreivier","dreiviereins",
"dreivierzwei","dreivierdrei","dreiviervier","viereins","vierzwei","vierdrei","viervier","viereinseins","viereinszwei",
"viereinsdrei","viereinsvier","vierzweieins","vierzweizwei","vierzweidrei","vierzweivier","vierdreieins",
"vierdreizwei","vierdreidrei","vierdreivier","vierviereins","viervierzwei","viervierdrei","vierviervier"];
document.getElementById(hide1).style.visibility ="hidden";
}
}
----------------------------------
as you see, the list under hide1 is far too long. I tried to assign a
variable to each string (var aaa = "einseinseins" ;). thus my hide 1
becomes shorter, but still too long. in a second step I tried to
combine these strings into groups. for instance, all string starting
with "vier..." could be grouped.
thus I hoped, that grouping the three varibles aa, ab and ac (which in
turn represent the strings "einseins", "einszwei" and "einsdrei") into
a new variable called a3. but I failed.
thanks for your help. max.
 
E

Evertjan.

max wrote on 31 okt 2006 in comp.lang.javascript:
Evertjan. schrieb:
[..]
var a3 = aa + ab + ac ; oder

Did you try, Max?
var a3 = (aa,ab,ac) ; oder wie??

Did you try, Max?
var a3 = aa + ab + ac ;

or (for strings concatenation):

var a3 = aa.concat(ab, ac);

Correct,
depending of what is ment by "Variablen zusammenfassen":

<http://dict.leo.org/ende?search=zusammenfassen>
<http://dict.leo.org/ende?search=concatenate>
<http://dict.leo.org/ende?search=addieren>

========

Perhaps you like this better:

var aa = "einseins";
var ab = "einszwei";
var ac = "einsdrei";
var a3 = [aa,ab,ac].join(' ');

Eins?

[Please do not toppost on usenet]

I don't get it working. here my layout:
var aa = "einseins"; var ab = "einszwei"; var ac = "einsdrei";
var a3 = aa + ab + ac ; // this should sum up the 3 vars above

You cannot "sum up" strings. You can concatenate them or you can change
them to numerals and then take the sum. Or you can put them in an array
or a collection.

function showEins() {
for (i = 0; i <=0; i++)
{
// show1 = [aa, ab, ac]; // with i<=2; this works, but is too long
in other cases

What do you mean by "to long"?

You do not use the "i" anywhere, so what do you mean?

show1 = [a3]; // does not work

What do you expext it to do?
It surely works, will be the same as:

var show1 = new Array(a3);

// var a3 = [aa,ab,ac].join(' '); // did not work either. do I have
to fill in the brackets?

No, see below
document.getElementById(show1).style.visibility ="visible";


That is very nice but has nothing to do with the above, I think.

Try this as a seperate file
[in general do not fill in adviced code in your not working code,
till you have tested it on its own]

========= test1.html =============
<script type='text/javascript'>
var aa = "einseins";
var ab = "einszwei";
var ac = "einsdrei";
var a3 = [aa,ab,ac].join(' ');

alert(a3)

</script>
=================================

Tested IE7

Does that "work" [= show the result string in an alert box]?

thank you. max.

Perhaps you want to do this:

========= test2.html =============
<table border=1><tr>
<td style='visibility:hidden;' id='einseins'>einseins</td>
<td style='visibility:hidden;' id='einszwei'>einszwei</td>
<td style='visibility:hidden;' id='einsdrei'>einsdrei</td>
</tr></table>

<script type='text/javascript'>
var aa = "einseins";
var ab = "einszwei";
var ac = "einsdrei";
var a3 = [aa,ab,ac];

function showEins() {
for (i = 0; i <=2; i++) {
document.getElementById(a3).style.visibility ="visible";
};
};

setTimeout('showEins()',3000);

</script>
=================================

Tested IE7
 
V

VK

depending of what is ment by "Variablen zusammenfassen":

By taking into account the response at
<http://groups.google.com/group/comp.lang.javascript/msg/70885fa51c7937ff>
we may translate "zu zusammenfassen" as "to finding the minimum subset
of elements corresponding to the given criteria" or (with the easiness
German solves such minor lexical problems which nocks me down every
time unless I'm there long enough and unless I had a pint of Metzkater
before to hear it :) that could be expressed as "zu
zusammenelentenausmachen".

To OP: actually arrays may have several "dimensions" and this is
what just scream asking to you:

[
// former eins
[
// former zwei
[
// former drei
]
]

]
 
O

Otto Lang

max said:
thanks for your detailed commentary.
what I need to do is simplifying a dynamic navigation for a website.
the navigation has three hierarchic levels. with each mouse rollover
some field show, others hide. this is defined in js as follows:
function showEinszwei() {
for (i = 0; i <=7; i++)
{
show1 = ["einseins", "einszwei", "einsdrei",
"einsvier","einszweieins", "einszweizwei", "einszweidrei",
"einszweivier"];
document.getElementById(show1).style.visibility ="visible";
}
for (i = 0; i <=71; i++)
{
hide1 =
["einseinseins","einseinszwei","einseinsdrei","einsdreifuenf",
"einsdreieins", "einsdreizwei", "einsdreidrei", "einsdreivier",
"einsviereins", "einsvierzwei", "einsvierdrei", "einsviervier",
[ too long ... snipped ]
}
}

as you see, the list under hide1 is far too long.

That's right.
I tried to assign a variable to each string (var aaa = "einseinseins"
;). thus my hide 1 becomes shorter, but still too long. in a second
step I tried to combine these strings into groups. for instance, all
string starting with "vier..." could be grouped.

You could try to group the items with regular expressions. If you are
not familiar with RegExp take a look at

<http://de.selfhtml.org/javascript/objekte/regexp.htm>
<http://de.selfhtml.org/navigation/syntax.htm#javascript>

and the functions test(), replace(), ...
thanks for your help. max.

HTH
../otto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top