Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set single quote in javascript

I want to set javascript variable with single quote. How it is possible. I am passing value to my function as parameter. and I am using this value to retrieve value of checkbox. So my problem is that if I am alerting value then it give me 'user' instead of 'sanjay' Here 'sanjay' is my value which is I am passing to parameter. And this will use to retrieve value of checkbox document.getElementById.

function single(user){

                var abc = '\' user \'';
                alert(abc);
                return false;
                var chksingle = document.getElementById(abc).checked;
                alert(chksingle);
                return false;
                if (userlist() === false)
                {
                    return false;
                }
                else
                {           
                        document.tallyexport.method = "post";
                        document.tallyexport.action = "checksingle.php";
                        document.tallyexport.submit();          
                }
            }
like image 216
LOKESH Avatar asked Nov 30 '15 03:11

LOKESH


1 Answers

Use string concatenation. The way you are doing it right now has user as part of the actual string, not using the variable.

var abc = "' " + user + " '"
like image 63
Iman K Avatar answered Sep 30 '22 11:09

Iman K