0

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
asked Mar 5, 2011 at 3:47
2
  • The function sample should be: function_name(55,document.form.field1.value, document.form.field2.value) Commented Mar 5, 2011 at 3:53
  • Voting to close ... not a real question and just gibberish unless revised. Commented Mar 5, 2011 at 4:02

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

2 Comments

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.
0

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);
answered Mar 5, 2011 at 4:05

1 Comment

just noticed @pst's answer, yes in the calling part you can use Array.join and in the function you can use String.split.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.