Solved

Javascript Issue Please Help

Posted on 2013-12-16
6
341 Views
Last Modified: 2014-01-10
I have a tab control and one of two potential tabs are displayed depending on the selected value of a dropdown box.  The problem is that for some reason whenever "BT10" is selected (and only "BT10") my javascript method breaks and I get the following error:

 JavaScript critical error  SCRIPT1004: Expected ';'

Below is my javascript method to toggle the tabs. If anybody could provide me with an insight as to why this is happening it would be greatly appreciated.

Jason

  function ToggleDamageandTheftTabs() {
              var tabStrip = eo_GetObject('<%=TabStrip1.ClientID%>');
              var typelossvalue = document.getElementById('ddlTypeLoss');
              var myvalue = typelossvalue.options[typelossvalue.selectedIndex].value;
              var tabItemTheft = tabStrip.getTopGroup().getItemByIndex(3);
              var tabItemDamage = tabStrip.getTopGroup().getItemByIndex(4);

              if (myvalue == "BT10") {

                  tabItemTheft.setVisible(true);
                  tabItemDamage.setVisible(false);
               }

              if (myvalue == "DAMAGE") {
                

                  tabItemTheft.setVisible(false);
                  tabItemDamage.setVisible(true);


              }

              if (myvalue == "THEFT") {

                  tabItemTheft.setVisible(true);
                  tabItemDamage.setVisible(false);
              }

              if (myvalue == "BD10") {

                  tabItemTheft.setVisible(false);
                  tabItemDamage.setVisible(true);
              }

             
               if (myvalue == "CD10") {

                  tabItemTheft.setVisible(false);
                  tabItemDamage.setVisible(true);
              }


              if (myvalue == "CT10") {

                  tabItemTheft.setVisible(true);
                  tabItemDamage.setVisible(false);
              }


              if (myvalue == "EIT10") {

                  tabItemTheft.setVisible(false);
                  tabItemDamage.setVisible(true);
              }


              if (myvalue == "EITUR10") {

                  tabItemTheft.setVisible(false);
                  tabItemDamage.setVisible(true);
              }


              if (myvalue == "EET") {

                  tabItemTheft.setVisible(true);
                  tabItemDamage.setVisible(false);
              }


          }

Open in new window

0
Comment
Question by:jazzcatone
6 Comments
 
LVL 7

Assisted Solution

by:dimmergeek
dimmergeek earned 166 total points
Comment Utility
Can we see the code for the HTML, specifically the drop-down list?  Can you provide a link?
0
 
LVL 25

Expert Comment

by:Lee Savidge
Comment Utility
STick an alert before the if statements outputting the value of myvalue. Consider changing the if statements to a switch statement.
0
 
LVL 35

Assisted Solution

by:mvidas
mvidas earned 167 total points
Comment Utility
To go along with what lsavidge said, here is your function using a switch statement for easier control. Note that it continues processing until it reaches a break, so we can use that to account for multiple cases:
function ToggleDamageandTheftTabs() {
              var tabStrip = eo_GetObject('<%=TabStrip1.ClientID%>');
              var typelossvalue = document.getElementById('ddlTypeLoss');
              var myvalue = typelossvalue.options[typelossvalue.selectedIndex].value;
              var tabItemTheft = tabStrip.getTopGroup().getItemByIndex(3);
              var tabItemDamage = tabStrip.getTopGroup().getItemByIndex(4);

              switch (myvalue) {
                  case "BT10":
                  case "THEFT":
                  case "CT10":
                  case "EET":
                      tabItemTheft.setVisible(true);
                      tabItemDamage.setVisible(false);
                      break;

                  case "DAMAGE":
                  case "BD10":
                  case "CD10":
                  case "EIT10":
                  case "EITUR10":
                      tabItemTheft.setVisible(false);
                      tabItemDamage.setVisible(true);
                      break;
              }
          }

Open in new window

Matt
0
 

Author Comment

by:jazzcatone
Comment Utility
This is unbelieveable. I took Matt's code and used his instead of mine. I still get the same exact  error !! Pretty crazy. For the dropdown I'm using a .net dropdownlist control. .

--Jason

  <asp:DropDownList ID="ddlTypeLoss" AutoPostBack="true"  runat="server" TabIndex="16" >
                                                        <asp:ListItem Value="" Text="SELECT"></asp:ListItem>
                                                        <asp:ListItem Value="DAMAGE" Text="DAMAGE"></asp:ListItem>
                                                        <asp:ListItem Value="THEFT" Text="THEFT"></asp:ListItem>
                                        </asp:DropDownList>

// also I have some C# code that populates it depending on the selection of another //dropdownlist

     protected void RebindddlTypeLossForURI()
        {
            if (ddlAccount.SelectedValue.Trim().ToUpper() == "URI2")
            {
                ddlTypeLoss.Items.Add(new ListItem("DAMAGE ON UR PREMISE", "BD10", true));
                ddlTypeLoss.Items.Add(new ListItem("THEFT FROM UR PREMISE", "BT10", true));
                ddlTypeLoss.Items.Add(new ListItem("RENTED EQUIPMENT DAMAGE", "CD10", true));
                ddlTypeLoss.Items.Add(new ListItem("RENTED EQUIPMENT THEFT", "CT10", true));
                ddlTypeLoss.Items.Add(new ListItem("EQUIPMENT DAMAGED IN TRANSIT OUTSIDE HAULER", "EIT10", true));
                ddlTypeLoss.Items.Add(new ListItem("EQUIPMENT DAMAGED IN TRANSIT UR HAULER", "EITUR10", true));
                ddlTypeLoss.Items.Add(new ListItem("EMPLOYEE TOOL LOSS", "EET", true));
            }
            else
            {


                string[] strArray = new string[] { "BD10", "BT10", "CD10", "CT10", "EIT10", "EITUR10", "EET" };

                int i = 0;
                for (i = 0; i < strArray.Length; i++)
                {
                    ListItem itemToRemove = ddlTypeLoss.Items.FindByValue(strArray[i]);
                    if (itemToRemove != null)
                    {
                        ddlTypeLoss.Items.Remove(itemToRemove);
                    }

                }



            }

        }

Open in new window

0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 167 total points
Comment Utility
Hi Jason,

please provide the whole generated HTML - the issue seems to be somewhere else and not inside the code behind.
Thanks.
Rainer
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now