I am using a javascript function and I am trying to pass a string of characters that come from form fields. I am trying to achieve this:
function_name(55,document,form.field1.value,form.field2.value)
but I am trying to pass the above as one argument, for example '44,55,66'
I tried the following without success:
'this.value+','.charAt(0)+document.class.Q_11_2c.value+','.charAt(0)+document.class.Q_12_3c.value'
ide
20.9k6 gold badges72 silver badges113 bronze badges
-
The function sample should be: function_name(55,document.form.field1.value, document.form.field2.value)Evan– Evan2011年03月05日 03:53:08 +00:00Commented Mar 5, 2011 at 3:53
-
Voting to close ... not a real question and just gibberish unless revised.user166390– user1663902011年03月05日 04:02:23 +00:00Commented Mar 5, 2011 at 4:02
2 Answers 2
If you want your function to accept a single argument, rewrite its definition accordingly and remove any charAt() from its argument in call.
answered Mar 5, 2011 at 3:53
Basilevs
24.7k16 gold badges61 silver badges110 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Evan
Thanks for taking the time to respond. But may I ask how can I pass as an argument a comma (,)?
@Evan "Serialize" to a string (Array.join) and "de-serialize" (String.split) later. However, this is a broken design -- it's hard to get correct (what if a comma comes in the data?) and just useless at this level. Perhaps update the post to include the end result for suggestions on how to correctly write the code.
your function:
function_name(dataString) {
//parse the param string to get values you need
//dataString.split("unique-delimiter")
}
now call it as:
//make values a single string and pass it to the function
//mydataString = dataArr.join("unique-delimiter") ;
function_name(mydataString);
1 Comment
bhu1st
just noticed @pst's answer, yes in the calling part you can use Array.join and in the function you can use String.split.
lang-js