Reputation: 19
How am I supposed to concatenate this?
here's my javascript code
var c0 = document.all.ntext.value;
var c1 = document.all.stext.value;
var x;
for(x=0; x<2; x++)
{
a.innerHTML = c //contatenation needed
}
Upvotes: 1
Views: 1730
Reputation: 160833
var needed = ['ntext', 'stext'];
a.innerHTML = needed.map(function(key) {
return document.all[key].value;
}).join('');
.map need a shim for old browsers.
Upvotes: 0
Reputation: 418
var c0 = document.all.ntext.value;
var c1 = document.all.stext.value;
var x;
for(x=0; x<2; x++)
{
a.innerHTML = c0 + с1
}
Is that what you want?
It'll be much better if you'll go this way:
var c = [document.all.ntext.value, document.all.stext.value];
var x;
for(x=0; x<c.length; x++)
{
a.innerHTML += c[0];
}
Upvotes: 1