Div/Layers problem in NN4

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lizzy

    #1

    Div/Layers problem in NN4

    I have an internet application which has a progress bar show whenever
    the customer is requesting data from the server. This progress bar is
    coded to work in both Netscape 4.75 and above and IE 5.0 and above.
    The progress bar code is written in javascript in an external js file
    (progressbar.js ). The web screen is in a seperate jsp file
    (Registration.j sp). The problem I'm having is that the progress bar is
    not showing in Netscape 4.75 on a MAC. I think it may have something
    to do with DIV located in the jsp file because if I comment the DIV,
    the progress bar shows up. I am using DIVs because when the form
    loads, the "divReservation Input" is visible and the "divMessage " is
    hidden. Then, when I call the progressbar.js, the "divMessage " is
    visible and the "divReservation Input" is hidden. I need help on
    properly coding this. Here is my code:

    The progress bar code is in an external js file (progressbar.js - code
    below):
    ------------------------------------------------------------------------------
    var NS4 = (document.layer s) ? true : false;
    var IE = (document.all) ? true : false;
    var blocksize = (barwidth-2)/waitTime/10;
    var loaded = 0;
    var ProgBar_outer;
    var ProgBar_done;
    var PBbckgnd;
    var Pid = 0;

    if(NS4)
    {
    document.write( '<ilayer name="ProgBar_o uter" id="ProgBar_out er"
    visibility="hid e" height="'+barhe ight+'" width="'+barwid th+'"
    onmouseup="hide bar()">');
    document.write( '<layer width="'+barwid th+'" height="'+barhe ight+'"
    bgcolor="'+bord ercolor+'" top="0" left="0"></layer>');
    document.write( '<layer width="'+(barwi dth-2)+'"
    height="'+(barh eight-2)+'" bgcolor="'+unlo adedcolor+'" top="1"
    left="1"></layer>');
    document.write( '<layer name="ProgBar_d one" id="ProgBar_don e"
    width="'+(barwi dth-2)+'" height="'+(barh eight-2)+'"
    bgcolor="'+load edcolor+'" top="1" left="1"></layer>');
    document.write( '</ilayer>');
    }
    else
    {
    document.write( '<div id="ProgBar_out er" onmouseup="hide bar()"
    style="position :relative; visibility:hidd en;
    background-color:'+borderc olor+'; width:'+barwidt h+'px;
    height:'+barhei ght+'px;">');
    document.write( '<div style="position :absolute; top:1px; left:1px;
    width:'+(barwid th-2)+'px; height:'+(barhe ight-2)+'px;
    background-color:'+unloade dcolor+'; font-size:1px;"></div>');
    document.write( '<div id="ProgBar_don e" style="position :absolute;
    top:1px; left:1px; width:0px; height:'+(barhe ight-2)+'px;
    background-color:'+loadedc olor+'; font-size:1px;"></div>');
    document.write( '</div>');
    }

    function progressBarInit ()
    {
    ProgBar_outer=( NS4)?findlayer( 'ProgBar_outer' ):(IE)?document .all['ProgBar_outer']:document.getEl ementById('Prog Bar_outer');
    ProgBar_done=(N S4)?ProgBar_out er.document.lay ers['ProgBar_done']:(IE)?document. all['ProgBar_done']:document.getEl ementById('Prog Bar_done');

    resizeElement(P rogBar_done,0,0 ,barheight-2,0);
    if(NS4)
    {
    ProgBar_outer.v isibility = "show";
    Pid = setInterval('in crCount()',95);
    }
    else
    {
    ProgBar_outer.s tyle.visibility = "visible";
    Pid = setInterval('in crCount()',95);
    }
    }

    function findlayer(name)
    {
    var i;
    for(i=0; i<document.laye rs.length; i++)
    {
    if(document.lay ers[i].name == name)
    {return(documen t.layers[i]);}

    if(document.lay ers[i].document.layer s.length > 0)
    {if((document.l ayers[i] = findlayer(name) ) != null)
    {return(documen t.layers[i]);}}
    }
    return null;
    }

    function resizeElement(i d,top,right,bot tom,left)
    {
    if(NS4)
    {
    id.clip.left = left;
    id.clip.top = top;
    id.clip.right = right;
    id.clip.bottom = bottom;
    }
    else
    {id.style.width = right + 'px'; }
    }

    function incrCount()
    {
    loaded++;
    if(loaded < 0)
    {loaded=0;}

    if(loaded >= waitTime*10)
    {
    clearInterval(P id);
    loaded = waitTime*10;
    setTimeout('hid ebar()',100);
    }
    resizeElement(P rogBar_done,0,b locksize*loaded ,barheight-2,0);
    }

    function hidebar()
    {
    clearInterval(P id);
    loaded=0;
    Pid = setInterval('in crCount()',95);
    }

    Registration.js p (code below):
    ------------------------------
    <HEAD>
    <title>Registra tion</title>
    <SCRIPT language="JavaS cript">
    <!--#include virtual="progre ssbar.js"-->
    var browserName = navigator.appNa me;
    var NS4 = (document.layer s) ? true : false;

    function submitForm()
    {
    showWaitMessage ();
    document.frmAdv ancedGuestRegis tration.submit( );
    }

    function showWaitMessage ()
    {
    if(NS4)
    {
    document.layers['divReservation Input'].visibility = 'hide';
    document.layers['divMessage'].visibility = 'show';
    }
    else
    {
    document.getEle mentById("divRe servationInput" ).style.visibil ity =
    "hidden";
    document.getEle mentById("divMe ssage").style.v isibility = "visible";
    }
    progressBarInit ();
    }
    </SCRIPT>
    </HEAD>

    <BODY bgcolor=3366cc>
    <jsp:useBean id="Reservation View" scope="session"
    class="com.view .ReservationInp utView"></jsp:useBean>

    <div id="divReservat ionInput"
    style="visibili ty:visible;posi tion:absolute;t op:16px;width:1 00%">
    <table width=650 border=0 cellpadding=0 cellspacing=0 align="center">
    <tr>
    <td colspan=4 bgcolor=#FFFFFF ><img src="images/arch_left.gif"
    width=182 height=26></td>
    <td width=31 height=26 bgcolor=#FFFFFF ><img
    src="images/spacer.gif"></td>
    <td colspan=4 bgcolor=#FFFFFF ><div align="right">< img
    src="images/arch_right.gif" width=271 height=26></div></td>
    </tr>
    <tr>
    <td width=166 height=291 bgcolor=#FFCC00 valign="top"><i mg
    src="images/spacer.gif"></td>
    <td width=484 height=291 colspan=9 valign="top"
    bgcolor="#FFFFF F"><br>
    <table width="95%" border="0" cellspacing="0" cellpadding="0"
    align="center">
    <tr>
    <td>
    <p><font face="Verdana, Arial, Helvetica, sans-serif"
    size="1">Please provide the following information to verify
    registration status.</font></p>

    <FORM name="frmRegist ration" method="POST" action="Servlet ">
    <table width="90%" border="0" cellspacing="0" cellpadding="2" >
    <tr>
    <td width="25%" height="20"><b> <font face="Verdana, Arial,
    Helvetica, sans-serif" size="1" color="3366CC"> Reservation
    Number</font></b></td>
    <td colspan="2" height="20"><in put type="text" name="txtResNbr "
    value="<%=Reser vationView.getR eservation().ge tReservationNum ber()%>"></td>
    </tr>
    <tr>
    <td width="25%" height="20">&nb sp;</td>
    <td width="27%" height="20" align="center"> <a
    href="javascrip t:checkForm()"> <img src="images/submit.gif" width="72"
    height="20" border="0"></a></td>
    <td width="38%" height="20">&nb sp;</td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </div>

    <div id="divMessage "
    style="visibili ty:hidden;posit ion:absolute;to p:16px;width:10 0%">
    <table width=650 border=0 cellpadding=0 cellspacing=0 align="center">
    <tr>
    <td colspan=9 bgcolor=#FFFFFF ><img src="images/tit_grf.gif" width=484
    height=20></td>
    </tr>
    <tr>
    <td width=166 height=291 bgcolor=#FFCC00 valign="top></td>
    <td width=484 height=291 colspan=9 valign="top"
    bgcolor="#FFFFF F"><br><br><br> <br><br>
    <FORM name="form1" method="POST" action="Servlet ">
    <table width="95%" border="0" cellspacing="0" cellpadding="0"
    align="center">
    <tr>
    <td align="center" height="30"><fo nt face="verdana" color="3366cc"
    size="2"><b>Sea rching For Your Reservation - Please
    Wait...</b></font></td>
    </tr>
    <tr>
    <td>
    <table align="center">
    <tr>
    <td><SCRIPT language="javas cript"
    src="./progressbar.js" ></SCRIPT></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>
    </div>

    <INPUT type="hidden" name="hdnNextPa ge"
    value="Advanced GuestRegistrati onSummary">
    <INPUT type="hidden" name="hdnAction "
    value="Retrieve RegistrationSum mary">
    </BODY>
    </HTML>
  • Dom Leonard

    #2
    Re: Div/Layers problem in NN4

    Lizzy wrote:[color=blue]
    > I have an internet application which has a progress bar show whenever
    > the customer is requesting data from the server. This progress bar is
    > coded to work in both Netscape 4.75 and above and IE 5.0 and above.
    > The progress bar code is written in javascript in an external js file
    > (progressbar.js ). The web screen is in a seperate jsp file
    > (Registration.j sp). The problem I'm having is that the progress bar is
    > not showing in Netscape 4.75 on a MAC. I think it may have something
    > to do with DIV located in the jsp file because if I comment the DIV,
    > the progress bar shows up.[/color]
    It looks like this is because errors in function findlayer are not being
    triggered when finding layers in the main document.

    I am using DIVs because when the form[color=blue]
    > loads, the "divReservation Input" is visible and the "divMessage " is
    > hidden. Then, when I call the progressbar.js, the "divMessage " is
    > visible and the "divReservation Input" is hidden.[/color]
    [color=blue]
    > The progress bar code is in an external js file (progressbar.js - code
    > below):
    > ------------------------------------------------------------------------------[/color]

    Supplied the following values for testing:

    var barwidth=302;
    var waitTime=3;
    var bordercolor="re d";
    var barheight="20";
    var loadedcolor="bl ue";
    var unloadedcolor=" white";
    [color=blue]
    > var NS4 = (document.layer s) ? true : false;
    > var IE = (document.all) ? true : false;
    > var blocksize = (barwidth-2)/waitTime/10;
    > var loaded = 0;
    > var ProgBar_outer;
    > var ProgBar_done;
    > var PBbckgnd;
    > var Pid = 0;
    >[/color]

    Including the .js file in the middle of a NS4 layer prevented function
    definitions from being in global scope when tested, so changed document
    write calls to creating a source string:

    var barHTML=""
    if(NS4)
    {
    barHTML+=('<ila yer name="ProgBar_o uter" id="ProgBar_out er"
    visibility="hid e" height="'+barhe ight+'" width="'+barwid th+'"
    onmouseup="hide bar()">');
    barHTML+=('<lay er width="'+barwid th+'" height="'+barhe ight+'"
    bgcolor="'+bord ercolor+'" top="0" left="0"></layer>');
    barHTML+=('<lay er width="'+(barwi dth-2)+'" height="'+(barh eight-2)+'"
    bgcolor="'+unlo adedcolor+'" top="1" left="1"></layer>');
    barHTML+=('<lay er name="ProgBar_d one" id="ProgBar_don e"
    width="'+(barwi dth-2)+'" height="'+(barh eight-2)+'"
    bgcolor="'+load edcolor+'" top="1" left="1"></layer>');
    barHTML+=('</ilayer>');
    }
    else
    {
    barHTML+=('<div id="ProgBar_out er" onmouseup="hide bar()"
    style="position :relative; visibility:hidd en;
    background-color:'+borderc olor+'; width:'+barwidt h+'px;
    height:'+barhei ght+'px;">');
    barHTML+=('<div style="position :absolute; top:1px; left:1px;
    width:'+(barwid th-2)+'px; height:'+(barhe ight-2)+'px;
    background-color:'+unloade dcolor+'; font-size:1px;"></div>');
    barHTML+=('<div id="ProgBar_don e" style="position :absolute; top:1px;
    left:1px; width:0px; height:'+(barhe ight-2)+'px;
    background-color:'+loadedc olor+'; font-size:1px;"></div>');
    barHTML+=('</div>');
    }

    (The parentheses are left over from the document.write and can be removed.)
    [color=blue]
    > function progressBarInit ()[/color]
    unchanged.

    Replaced[color=blue]
    > function findlayer(name)
    > {
    > var i;
    > for(i=0; i<document.laye rs.length; i++)
    > {
    > if(document.lay ers[i].name == name)
    > {return(documen t.layers[i]);}
    >
    > if(document.lay ers[i].document.layer s.length > 0)
    > {if((document.l ayers[i] = findlayer(name) ) != null)
    > {return(documen t.layers[i]);}}[/color]

    (This will loop if the layer sought is in a nested layer)
    [color=blue]
    > }
    > return null;
    > }[/color]

    with

    function findDocumentLay er(document, name)
    {
    var i;
    var layer=null;
    for(i=0; (i < document.layers .length) && !layer;)
    { layer=document. layers[i++];
    if(layer.name!= name)
    layer=findDocum entLayer(layer. document, name);
    }
    return layer;
    }
    function findlayer(name)
    {
    return findDocumentLay er(document, name);
    }

    Feel free to rewrite in your own style. The remainder of progressbar.js
    was unchanged.

    <trim>

    In registration.js p progress bar code can now be included in the head
    section:

    <script type="text/javascript" src="progressba r.js"></script>
    [color=blue]
    > <SCRIPT language="JavaS cript">[/color]
    The type attribute is mandatory, see script tag above.
    [color=blue]
    > <BODY bgcolor=3366cc>[/color]

    The HTML spec calls for "#3366cc". I suggest color value usage, and
    quoting of attribute values throughout the page be upgraded.

    <trim>
    [color=blue]
    > <div id="divMessage "
    > style="visibili ty:hidden;posit ion:absolute;to p:16px;width:10 0%">
    > <table width=650 border=0 cellpadding=0 cellspacing=0 align="center">
    > <tr>
    > <td colspan=9 bgcolor=#FFFFFF ><img src="images/tit_grf.gif" width=484
    > height=20></td>
    > </tr>
    > <tr>
    > <td width=166 height=291 bgcolor=#FFCC00 valign="top></td>[/color]

    The unterminated valign value causes this tag to go missing. I suggest
    validating the HTML in any case, but this line should be changed to

    <td width="166" height="291" bgcolor="#FFCC0 0" valign="top"></td>

    <trim>
    [color=blue]
    > <td><SCRIPT language="javas cript"
    > src="./progressbar.js" ></SCRIPT></td>[/color]

    changed script tag to

    <SCRIPT type="text/javascript">doc ument.write(bar HTML);</SCRIPT>


    The above changes got the basic concept to work in multiple browsers
    but, of course, the page remains unfinished. HTH and good luck!

    Dom

    Comment

    Working...