donz4
asked on
javascript - converting from var array to string
I'm using a javascript to populate an array defined as:
var typearray = new Array();
then, I need to set a hidden field in the html to this value. I tried:
document.sortForm.typearra y.value = typearray;
and:
document.sortForm.typearra y.value = typearray.toString();
but when I display the value it shows as [object] and when I try to use it in my servlet the value is garbage.
How do I pass this array as a string by using hidden fields in my html?
var typearray = new Array();
then, I need to set a hidden field in the html to this value. I tried:
document.sortForm.typearra
and:
document.sortForm.typearra
but when I display the value it shows as [object] and when I try to use it in my servlet the value is garbage.
How do I pass this array as a string by using hidden fields in my html?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could try this javascript array method. I saw this in a book.
document.sortForm.hidden.v alue = typearray.join();
or use
document.sortForm.hidden.v alue = typearray.join(separator);
Now, do want us to give code for parsing this value on the JSP side ? rrz
document.sortForm.hidden.v
or use
document.sortForm.hidden.v
Now, do want us to give code for parsing this value on the JSP side ? rrz
> document.sortForm.hidden.v alue = typearray.join();
Nice! :-D
Nice! :-D
Something like this;
var typearray = new Array();
var oSpan = document.getElementById("" );
oSpan.innerHTML = typearray [0]; // append each array element to the span's contents
and so on---
Did you get the idea?
--Raj
var typearray = new Array();
var oSpan = document.getElementById(""
oSpan.innerHTML = typearray [0]; // append each array element to the span's contents
and so on---
Did you get the idea?
--Raj
So if you had:
valuearray = new Array( 3 ) ;
valuearray[ 0 ] = 'hello' ;
valuearray[ 2 ] = 'there' ;
valuearray[ 3 ] = 'tim' ;
the hidden field will be set to
"hello,there,tim"