• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2219
  • Last Modified:

CS1012: Too many characters in character literal

I am getting this error, when attempting to execute javascript function switchViews statement:
     var img = document.getElementById('img' + obj);

ASP:
<a href="javascript:switchViews('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.
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";
               }
       }

Open in new window

0
ssmacwilliams
Asked:
ssmacwilliams
  • 2
1 Solution
 
techExtremeCommented:
If you are getting error at line var img = document.getElementById('img' + obj);
 and
If you are passing partial element id in the 'obj' variable, then I guess you should try this out:

document.getElementById("'img" + obj + "'");


0
 
ssmacwilliamsAuthor Commented:
Explanation wasn't given. Solution suggested worked, but passing the additional concatenation of a quote wasn't necessary.
0
 
techExtremeCommented:
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
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now