Solved

Javascript Issue Please Help

Posted on 2013-12-16
6
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 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…
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 …
Suggested Courses

623 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