tags:

views:

171

answers:

3

We found a JQuery plugin called FixedTable that is used to add scroll bars to an HTML table, and I've copied their sample code (see below) from their website into a ASP.Net web form. Each time the code executes it blows up on line 12, the $(".tableDiv").each(function(), saying that an Object was Expected. Anyone know what is wrong with this code?

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="fixedtable.aspx.cs"       Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
    <script type="text/javascript" src="~/js/jquery-1.3.2-vsdoc2.js"></script>
    <script type="text/javascript" src="~/js/jquery.fixedtable.js"></script>
<script type="text/javascript">
    // this "tableDiv" must be the table's class
    $(".tableDiv").each(function() {
        var Id = $(this).get(0).id;
        var maintbheight = 555;
        var maintbwidth = 911;

        $("#" + Id + " .FixedTables").fixedTable({
            width: maintbwidth,
            height: maintbheight,
            fixedColumns: 1,
            // header style
            classHeader: "fixedHead",
            // footer style        
            classFooter: "fixedFoot",
            // fixed column on the left        
            classColumn: "fixedColumn",
            // the width of fixed column on the left      
            fixedColumnWidth: 150,
            // table's parent div's id           
            outerId: Id,
            // tds' in content area default background color                     
            Contentbackcolor: "#FFFFFF",
            // tds' in content area background color while hover.     
            Contenthovercolor: "#99CCFF",
            // tds' in fixed column default background color   
            fixedColumnbackcolor: "#187BAF",
            // tds' in fixed column background color while hover. 
            fixedColumnhovercolor: "#99CCFF"
        });
    });
</script>
<style type="text/css">
    body
    {
        width: 900px;
    }
    p
    {
        float:left;
        width: 100%;
        margin: 20px 0px;
    }
    .fixedColumn .fixedTable td
    {
        color: #FFFFFF;
        background-color: #187BAF;
        font-size: 12px;
        font-weight: normal;
    }

    .fixedHead td, .fixedFoot td
    {
        color: #FFFFFF;
        background-color: #187BAF;
        font-size: 12px;
        font-weight: normal;
        padding: 5px;
        border: 1px solid #187BAF;
    }
    .fixedTable td
    {
        font-size: 8.5pt;
        background-color: #FFFFFF;
        padding: 5px;
        text-align: left;
        border: 1px solid #CEE7FF;
    }
    .tableDiv 
    {

    }
</style>


</head>
<body>
    <form id="form1" runat="server">
    <div id="tableDiv_Arrays" class="tableDiv">
    <table id="Open_Text_Arrays" class="FixedTables">
        <thead>
            <tr>
                <th>
                    Purpose
                </th>
                <th>
                    C#
                </th>
                <th>
                    Php4
                <th>
                <th>
                    Php5
                </th>
                <th>
                    ActionScript
                </th>
                <th>
                    JavaScript
                </th>
                <th>
                    Ruby
                </th>
            </tr>
        <thead>
        <tbody>
            <tr>
                <th>
                    data1
                </th>
                <th>
                    data2
                </th>
                <th>
                    data3
                <th>
                <th>
                    data4
                </th>
                <th>
                    data5
                </th>
                <th>
                    data6
                </th>
                <th>
                    data7
                </th>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <th>
                    Purpose
                </th>
                <th>
                    C#
                </th>
                <th>
                    Php4
                <th>
                <th>
                    Php5
                </th>
                <th>
                    ActionScript
                </th>
                <th>
                    JavaScript
                </th>
                <th>
                    Ruby
                </th>
            </tr>
        </tfoot>
    </table>
</div>

</form>
</body>
</html>
A: 

To get an 'object expected' error there, jQuery must not even be loading. What's with the src="~/js/jquery-1.3.2-vsdoc2.js" attributes in the script tags, with the tildes? Is that something your web server will make sense of, or is it as wrong as it looks? Anyway, in some fashion, your script tags are not referring to your jQuery source files in a way that works.

Further, when you get that sorted, the tableDiv doesn't exist when the script content is run. You'll need to put the script in a $(document).ready().

chaos
This should not cause a js error however.
redsquare
The ways of IE are mysterious and horrible, but you're probably right. An "object was expected" sounds like jQuery isn't even loading. Gotta say, I'm real suspicious of those tildes in the script src attributes; I'd assumed they were something that the OP's environment would make sense of, but perhaps not.
chaos
The tildes did turn out to be a problem, I removed those and checked firebug to make sure the jquery files are loading properly and they are now, and I added the document.ready() function. I'm getting a table now, no error messages, but no scroll bar. Any other ideas?
Russ Clark
A: 

Are you sure jQuery is being requested correctly? You can check this by using fiddler2 or firebug in firefox.

Also you will need the document ready function. This ensures the dom is ready before you start to manipulate it.

$(function(){

   $(".tableDiv").each(function() {
        var Id = $(this).get(0).id;
        var maintbheight = 555;
        var maintbwidth = 911;

        $("#" + Id + " .FixedTables").fixedTable({
            width: maintbwidth,
            height: maintbheight,
            fixedColumns: 1,
            // header style
            classHeader: "fixedHead",
            // footer style        
            classFooter: "fixedFoot",
            // fixed column on the left        
            classColumn: "fixedColumn",
            // the width of fixed column on the left      
            fixedColumnWidth: 150,
            // table's parent div's id           
            outerId: Id,
            // tds' in content area default background color                     
            Contentbackcolor: "#FFFFFF",
            // tds' in content area background color while hover.     
            Contenthovercolor: "#99CCFF",
            // tds' in fixed column default background color   
            fixedColumnbackcolor: "#187BAF",
            // tds' in fixed column background color while hover. 
            fixedColumnhovercolor: "#99CCFF"
        });
    });

};

redsquare
I tried adding the document ready function, but still getting the same error. Also, I have firebug, but not sure how to check to see if jquery is loading properly, can you expand on that?
Russ Clark
Sure. Use the net tab - press ctrl+f5. This shows a list of all the requests that are made for the document. Any red requests indicate an error.
redsquare
A: 

Or place the script block between the </body> and </html> tags at the end of your file.

Hans B PUFAL
well before the closing body tag yeah
redsquare