I want to pass string and integer parameters through a javascript function, but the integer passes as string.
The variable attachfile is a string.
var upload_number = 1;
input.setAttribute("onClick", "removeBtn(attachfile+ upload_number)");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It would help if you showed the declaration for your
removeBtn()function, but the problem seems to be that you are not passing two parameters to the function, you are passing one parameter that takes the value ofattachfileconcatenated withupload_number– and when you concatenate a string with a number the result is a string.You need to pass the parameters separately, i.e., instead of:
Use:
Then the declaration of
removeBtn()should be:(By the way, the way you are setting the
onclickattribute to a string that contains a function call may also be causing you some problems because (amongst other issues) that function and the parameters would need to be globals. But that’s – possibly – outside the scope of this question, at least unless you update it to show more of your code.)