Solved

JQuery Tab Null Value Error

Posted on 2014-10-10
1
272 Views
Last Modified: 2014-10-13
I have a JQuery Tab Container.  One of the tabs I have a aspx page with a search box that filers results. When I call the page from the Tab Container and run the filter I get an " Unable to set property 'value' of undefined or null reference" error message. However, when I run the search page independently I do not get any errors.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <meta charset="utf-8">
  <title></title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
    <script src="Scripts/jquery-2.1.1.min.js"></script>
    <script src="Scripts/jquery-ui.min-1.11.1.js"></script>
  <script>
      $(function () {
          $("#tabs").tabs({
              beforeLoad: function (event, ui) {
                  ui.jqXHR.error(function () {
                      ui.panel.html(
                        "Couldn't load this tab. Please try again!");
                  });
              }
          });
      });
  </script>
</head>
<body>
    <form id="form1" runat="server">
  <div id="tabs" runat="server">
      <ul>
        <li><a href="Search.aspx" id="link1" runat="server">Search</a></li>
        <li><a href="#tab2" id="link2" runat="server">Links</a></li>
        <li><a href="#tab3" id="link3" runat="server">Calendar</a></li>
      </ul>
  <div id="tab1" runat="server" />
  <div id="tab2" runat="server" />
  <div id="tab3" runat="server" />
  </div>
    </form>
</body>
</html>

Open in new window


<head>
<script type = "text/javascript">
    var ddlText, ddlValue, ddl, lblMesg;
    function CacheItems() {
        ddlText = new Array();
        ddlValue = new Array();
        ddl = document.getElementById("<%=PersonList.ClientID %>");
        lblMesg = document.getElementById("<%=lblMessage.ClientID%>");
        for (var i = 0; i < ddl.options.length; i++) {
            ddlText[ddlText.length] = ddl.options[i].text;
            ddlValue[ddlValue.length] = ddl.options[i].value;
        }
    }
    window.onload = CacheItems;

    function FilterItems(value) {
        ddl.options.length = 0;
        for (var i = 0; i < ddlText.length; i++) {
            if (ddlText[i].toLowerCase().indexOf(value) != -1) {
                AddItem(ddlText[i], ddlValue[i]);
            }
        }
        lblMesg.innerHTML = ddl.options.length + " matches";
        if (ddl.options.length == 0) {
            AddItem("No matches", "");
        }
    }

    function AddItem(text, value) {
        var opt = document.createElement("option");
        opt.text = text;
        opt.value = value;
        ddl.options.add(opt);
    }
</script>
</head>
<body>
            <div id="PersonFind">
                <asp:TextBox ID="Search" Width="300px" onkeyup="FilterItems(this.value)" runat="server" /><asp:Button ID="FindPerson" Text="Find" runat="server" OnClick="FindPerson_Click" />
                <br />
                <asp:Label ID="lblMessage" runat="server"></asp:Label>
                <br />
                <asp:ListBox ID="PersonList" Width="300px" AutoPostBack="true" OnSelectedIndexChanged="PersonList_SelectedIndexChanged"  SelectionMode="Single" Height="300px" runat="server" />
            </div>
</body>

Open in new window

0
Comment
Question by:RecipeDan
[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
1 Comment
 
LVL 29

Accepted Solution

by:
Pravin Asar earned 500 total points
ID: 40374334
You can simplify select/listbox add . for example:   htmlSelect.add(new Option(text, dvalue));

In your case :

function AddItem(text, value) {
        if (ddl) {
                       ddl.options.add(new Option(text, value) );
        }
    }
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 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