How to set single quote in javascript

I want to set a single quote javascript variable. How is this possible. I pass the value of my function as a parameter. and I use this value to get the checkbox value. So my problem is that if I warn about the value, then it gives me a β€œuser” instead of β€œsanjay”. Here "sanjay" is my value, which I pass to the parameter. And this will be used to retrieve the checkbox value of 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(); } } 
+5
source share
1 answer

Use string concatenation. The way you do this now has user as part of the actual string without using a variable.

 var abc = "' " + user + " '" 
+7
source

Source: https://habr.com/ru/post/1237081/


All Articles