Solved

JQuery Tab Null Value Error

Posted on 2014-10-10
1
267 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
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Popup write two lines 3 22
What is the correct way to check for empty value in input field 2 20
HTML editor custom button 3 60
toggle content 12 26
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

726 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