/    Sign up×
Community /Pin to ProfileBookmark

Display/Hide Div…

Hello All,

I’m running into a little trouble trying to display a hidden div…

[QUOTE]

function DisplayNav(in_strName, in_obj)
{
if (strCurrentDisplay != in_strName)
{
strCurrentDisplay = in_strName;

document.getElementById(‘Practice’).style.display=’none’;
document.getElementById(‘Tournaments’).style.display=’none’;
document.getElementById(‘Archive’).style.display=’none’;
document.getElementById(‘Photos’).style.display=’none’;

document.getElementById(in_strName).style.display=”;
}

}

[/QUOTE]

Hiddend Div

[QUOTE]

<div id=”Photos” style=”DISPLAY: none”>
<table border=”0″ width=”800″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”100%”>
<table border=”0″ width=”100%” cellspacing=”0″ cellpadding=”3″>
<tr>
<td width=”100%”><p align=”center”><b><font face=”Arial” size=”5″>Team Photos</font></b></td>
</tr>
<tr>
<td width=”100%”>soon…</span></td>
</tr>
</table>
</td>
</tr>
</table>
<hr noshade size=”5″ width=”800″ align=”left”>
</div>

[/QUOTE]

The link to display the Div (and hide others)

[QUOTE]

<A href=”javascript?isplayNav(‘Photos’)”>Practice Schedule</A>

[/QUOTE]

The error I get is…

[B]error object expected.[/B]

Any help is much appreciated.

~Thanks, Jim

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@baconbuttyDec 13.2004 — Hi

"error object expected" suggests:-

(a) It is not finding the function DisplayNav, or

(b) It is not finding one of your element id's, or

(c) Some error in some other part of your code.

  • 1. You will need to confirm which code line you are getting the object expected on. The browser should give you the line number. For instance, is it managing to find (check spelling):-


  • [CODE]

    document.getElementById('Practice').style.display='none';
    document.getElementById('Tournaments').style.display='none';
    document.getElementById('Archive').style.display='none';

    [/CODE]


  • 2. There seems to be a space between "java" and "script" in your example:-




  • <A href="java script?isplayNav('Photos')">Practice Schedule</A>

    [/QUOTE]


  • 3. If you want to activate a Javascript function it is preferable to use the "onclick" event (although it probably will not make any difference):-


  • [CODE]

    <p onclick="DisplayNav('Photos')">Practice Schedule</p>

    [/CODE]
    Copy linkTweet thisAlerts:
    @gamegeezerauthorDec 13.2004 — Hello baconbutty,

    The error occurs at the Href or OnClick...

    DisplayNav('Practice')[/QUOTE]

    I appreiciate the help.

    ~Thanks, Jim
    Copy linkTweet thisAlerts:
    @gamegeezerauthorDec 13.2004 — Howdy all,

    Here is the code, I could swear this has worked for me in the past...

    [URL=http://www11.brinkster.com/seattlegould/test.asp]code[/URL]

    ~Thanks much, Jim
    Copy linkTweet thisAlerts:
    @baconbuttyDec 14.2004 — Ah-ha.

    Looking at your code, there are two things:-


  • 1. The script tag - which you omitted from your extracts ?


  • [CODE]

    <script language="JavaScript" [U]for="window" event="onload"[/U]>

    [/CODE]


    Delete the underlined part. This stops the script from being global (i.e. it makes it a private function for the window onload event), and so the function DisplayDIV is not available globally to the rest of the page.

  • 2. Define your variables


  • You need to define strCurrentDisplay somewhere e.g.:-

    [CODE]
    <script language="JavaScript">

    [B] var strCurrentDisplay=null;[/B]

    function DisplayDIV(in_strName, in_obj)
    {


    [/CODE]
    ×

    Success!

    Help @gamegeezer spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.20,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...