tags:

views:

49

answers:

3

Hi everyone,

I have 3 variables and I was wondering how to join their values and add them to a hidden field,

   document.getElementById('my-item-name').value = meat.join("\t");

it works for 1 but when I add the other variable it doesn't work.

  document.getElementById('my-item-name').value = meat.join("\t").veg.join("\t").sause.join("\t");

the variables are meat, veg, and sauce.

thanks

A: 

Just use the '+' operator:

document.getElementById('my-item-name').value = meat + "\t" + veg + "\t" + sause;
too much php
+4  A: 

I think you are trying to concatenate the variables:

document.getElementById('my-item-name').value = meat + "\t" + veg + "\t" +
                                                sause + "\t";

The join function is applied to Arrays, you could use it also:

document.getElementById('my-item-name').value = [meat,veg,sause].join('\t');
CMS
A: 

document.getElementById('my-item-name').value = meat + "\t" + veg + "\t" + sause + "\t";

Kombuwa