Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

Javascript Issue Please Help

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
jazzcatone
Asked:
jazzcatone
3 Solutions
 
dimmergeekCommented:
Can we see the code for the HTML, specifically the drop-down list?  Can you provide a link?
0
 
Lee SavidgeCommented:
STick an alert before the if statements outputting the value of myvalue. Consider changing the if statements to a switch statement.
0
 
mvidasCommented:
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
 
jazzcatoneAuthor Commented:
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
 
Rainer JeschorCommented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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