Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Required Error

Status
Not open for further replies.
Oct 11, 2006
300
US
Hi,

I built a small ASP page which pulls the top level category "Beverage" from Northwind database. When I click on the link, Beverage, I can see all the products that fall under the category "Beverage". However I would like to click on the link again to hide the products and click on the link again to see the products. To do so, I have a function that shows and hides a UL tag list.

I get an object required error whenever I click on the link at line 57.

Here is my Javascript funtion:

Code:
function s_Hide(el){
	alert("Showing Element: "+el);
	objID = 'UI_'+el;
	alert(objID);
	obj = document.getElementById(objID).style;
	(obj.display == 'none')? obj.display = 'block' : obj.display = 'none';
}

For your information, I have 2 Javascript functions that associated with the onClick event. 2nd one is as follows:

Code:
function showProducts(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}

var url="getProducts.asp"
url=url+"?ID="+str
//alert(url);
//url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

HTML Line where I get the error is below in bold:

Code:
<ul id="menu">
        <li>
            <input type="radio" checked name="prodid" id="Catid1" value="1">
            [b]<a href="#" class="a_style" onclick="showProducts(1);s_Hide('1');">Beverages</a>[/b]
            <ul id="UI_1">
            
            <div id="content_products">
            </div>
            </ul>
        </li>
    </ul>

Any tips what I am doing wrong?

Thanks.
 
S_Hide(el) function is declared within the script tag of the same file. Though the same script has a src which points to an external Javascript (js) file too.

I made the changes to this:

Code:
<a href="#" class="a_style" onclick="showProducts(2);s_Hide('2'); return false;">Condiments</a>

But I still get the same error as before on the same line.

Thanks.
 
Your comment "Where is it declared" got me thinking...

I had s_Hide(el) function declared within the page and also had a src attribute for the script tag pointing to getProducts.js tag

So it was looking for the object in the external file and not the embedded function within the page.

I moved all the functions to the exisiting file and I do not get any object error now.

Thanks.
 
But does not Javascript work like the way CSS files work. I have pages where the link to the CSS file is declared and I also have an embedded CSS classes defined within the page.

Thanks.
 
Js declarations work in source order... so if you define something locally first, then override it in an external file, the external one will "win" scope. If the external file is included first, the local one will "win" scope.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top