Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have following script in my page to highlight a map.

C#
<script>
    function highlight(list,win,lose)
    {
        var WinParty = win;
        var LoseParty = lose;

        var jsVariable = list;

        var area = document.getElementsByTagName('area')
        var ary=[]
        for (var zxc0=0;zxc0<area.length;zxc0++){
            ary.push(area);
           }

        var isfound = false;

        for(var i = 0; i < area.length; i++)
        {
            isfound = false;

            for(var j = 0; j < jsVariable.length; j++)
            {
                if (area[i].getAttribute('title').trim() == jsVariable[j].trim())
                {
                    isfound = true;
                    $(area[i]).each(function ()//get all areas
                    {
                        $(this).addClass("victory");
                    });
                }
            }
            if(!isfound)
            {
                $(area[i]).each(function ()//get all areas
                {
                    $(this).addClass("lose");
                });
            }
        }

        $(function () {
            var data = {};
            $('.map').maphilight();
            data.alwaysOn = true;
            data.fillColor = WinParty;
            $('.victory').data('maphilight', data).trigger('alwaysOn.maphilight');


            var data = {};
            $('.map').maphilight();
            data.alwaysOn = true;
            data.fillColor = LoseParty;
            $('.lose').data('maphilight', data).trigger('alwaysOn.maphilight');
        });
    }
</script>



I am calling this script from Code Behind (VB.Net) as follows

VB
Dim Serializer = New System.Web.Script.Serialization.JavaScriptSerializer()
Dim List = Serializer.Serialize(Values)
WinPartyColor = Hex(Color.Blue.ToArgb()).Substring(2)
LosePartyColor = Hex(Color.Red.ToArgb()).Substring(2)

Dim Script As String = String.Format("highlight({0},{1},{2});", List, WinPartyColor, LosePartyColor)

ScriptManager.RegisterStartupScript(ElectionResultUpdatePanel, ElectionResultUpdatePanel.GetType(), "HighLighting", Script, True)


When i'm running above code in Chrome i'm getting error as

Uncaught SyntaxError: Unexpected identifier

but when i run same code in IE, getting error as

SCRIPT1007: Expected ']'.

My guess is about List argument, which is array in Javascript.

Please help me out.
Posted
Updated 18-Jul-14 18:36pm
v2

1 solution

Finally I fixed the problem,

It is cause of calling script from Code behind:

VB
Dim Script As String = String.Format("highlight({0},{1},{2});", List, WinPartyColor, LosePartyColor)


I have change is as follows, now it's working fine.

VB
Dim Script As String = "highlight(" + List + ",'" + WinPartyColor + "','" + LosePartyColor + "');"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900