ssmacwilliams
asked on
CS1012: Too many characters in character literal
I am getting this error, when attempting to execute javascript function switchViews statement:
var img = document.getElementById('i mg' + obj);
ASP:
<a href="javascript:switchVie ws('div<%# Eval("CustomerID") %>', 'one');">
<img id="imgdiv<%# Eval("CustomerID") %>" alt="Click to show/hide orders" border="0" src="Images/plus-8.png" /> </a>
I saw 2 resolutions in Experts exchange; but don't understand their resolution to the problem. I recognize that this is calling a clientside function vs a serverside; And that it is being interpreted as ServerSide. Simple explanation and resolution requested.
var img = document.getElementById('i
ASP:
<a href="javascript:switchVie
<img id="imgdiv<%# Eval("CustomerID") %>" alt="Click to show/hide orders" border="0" src="Images/plus-8.png" /> </a>
I saw 2 resolutions in Experts exchange; but don't understand their resolution to the problem. I recognize that this is calling a clientside function vs a serverside; And that it is being interpreted as ServerSide. Simple explanation and resolution requested.
function switchViews(obj,row)
{
var div = document.getElementById(obj);
var img = document.getElementById('img' + obj);
if (div.style.display=="none")
{
div.style.display = "inline";
if (row=='alt')
{
img.src="Images/minus-8.png" mce_src="Images/minus-8.png";
}
else
{
img.src="Images/plus-8.png" mce_src="Images/plus-8.png";
}
img.alt = "Close to view other customers";
}
else
{
div.style.display = "none";
if (row=='alt')
{
img.src="Images/minus-8.png" mce_src="Images/minus-8.png";
}
else
{
img.src="Images/plus-8.png" mce_src="Images/plus-8.png";
}
img.alt = "Expand to show orders";
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
thanks. l thought that would suffice. Anyways, in javascript when you need to refer to any element using getElementById, you must pass the id as string in single quotes or double quotes. that means if my variable name is img0001 and if i'm passing the strin '0001' in obj and 'img' is hardcoded,
I must concat both 'img' and '0001' before passing it to get element by id, that's what we did by that line. Now its totally upto what you send in 'Obj' variable to do this. If you are directly passing object , no need of getElementById.
Anyways if that has solved your problem may be this will help you in future.
Thanks
I must concat both 'img' and '0001' before passing it to get element by id, that's what we did by that line. Now its totally upto what you send in 'Obj' variable to do this. If you are directly passing object , no need of getElementById.
Anyways if that has solved your problem may be this will help you in future.
Thanks
ASKER