0
How do I prevent user input (array)from being turned to a string
If an input type is 'text', whatever the user inputs will be a String. I am collecting arrays from user input and feed it as an argument to my function but the array comes as a string. Hiw can I maintain the array. For example the inout below is intended to return the array as is, not as '[[1,2,3,4],[1,2,3]]' <input type="text" name ="arguments" value="[[1,2,3,4],[1,2,3]]" id="argument"/> I know there are other types of inputs but no array. Thanks.
3 Réponses
+ 5
Because with the value attribute ( as all html/xml attributes ) you don't have other way than handle strings, you should decode your user entry by using the split() method of javascript arrays, as be suggest by @cheeze...
Another way to decode ( and encode if needed ) is by using the JSON.parse() function ( decoding a string into JS object -- the encoding version is JSON.stringify() ): usefull for handling JS object as string, and share data beetween programs/languages ( ie: communication with servers ), JSON ( JavaScript Object Notation ) is a widely standard format, based on JS objects notation, for textual representation of data :)
+ 2
.split(",")
0
I get it, there is no way other than manipulating the inputed text into a format you want. thanks