brgdotnet
asked on
How to single quote a check box id using java script before using document.GetElementById ?
I can check a checkbox as follows using Java Script :
document.getElementById('C heckbox2') .checked = true;
It works because Checkbox2 is wrapped in single quotes. So how can I wrap single quotes around
the check box name when the name is passed into the function "startTheProcess"?
I tried something like this, but it does not work on line 4 : checkTheBox( + "'" + CheckBoxId + "'" + );
1 function startTheProcess(CheckBoxId )
2 {
3 // If the value passed in for CheckBoxId is not single quoted. How do I single quote it?
4 checkTheBox(CheckBoxId);
5}
function checkTheBox(CheckBoxId)
{
document.getElementById(Ch eckBoxId). checked = true;
// document.getElementById('C heckbox2') .checked = true; // This works, but is hard coded
}
document.getElementById('C
It works because Checkbox2 is wrapped in single quotes. So how can I wrap single quotes around
the check box name when the name is passed into the function "startTheProcess"?
I tried something like this, but it does not work on line 4 : checkTheBox( + "'" + CheckBoxId + "'" + );
1 function startTheProcess(CheckBoxId
2 {
3 // If the value passed in for CheckBoxId is not single quoted. How do I single quote it?
4 checkTheBox(CheckBoxId);
5}
function checkTheBox(CheckBoxId)
{
document.getElementById(Ch
// document.getElementById('C
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the extra space is typo, and yeah, in the signature of the function I forgot the second parameter. Anyway, I still cannot get it to work. On the java scriptyup, typo does affect results.
side I tried adding two single quotes to the variable passed in, but that does not work either?
how's your codes look like now? did you clear the browser's cache before retry your page?
ASKER
Well I didn't quite get the answer I wanted, but I think you guys brought me closer to a way think of it differently. Thank you.
You're welcome, glad to help.
Well I didn't quite get the answer I wantedI thought Ryan had answered your question so I deleted my response which I assumed was a duplicate. I am reposting here in case it is useful.
The gist of it is that you are calling your show() with two parameters but it only takes one - because the checkbox id is the second parameter the show() function never sees it
Let's look at your code
string showPopup = "return show('" + e.Row.Cells[data.Row.Table.Columns["CustId"] + " ' , ' " + cbxBox.ID.ToString() + " ');";
This will render something like this<input type="checkbox" onclick="return show('CustID001','Checkbox1')" ... />
show is defined asfunction show(theckbox) {
Notice the difference in the parameters - your function expects 1 is being sent 2 so you are using the customerID to try and target the checkboxEither change your C# code to only send one parameter
string showPopup = "return show('" + cbxBox.ID.ToString() + " ');";
Or change your function to accept the customerID - not sure why you would do this though as you don't seem to use itfunction show(custID, theckbox) {
ASKER
side I tried adding two single quotes to the variable passed in, but that does not work either?