Solved

Javascript Issue Please Help

Posted on 2013-12-16
6
360 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
ID: 39721772
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
ID: 39721776
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
ID: 39721788
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
ID: 39721868
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
ID: 39723949
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

830 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