Click to See Complete Forum and Search --> : Im in truble with div tag and Netscape 4.7.


DubsJoy
10-22-2003, 12:24 PM
Hi everyone,
Im in truble with div tag and Netscape 4.7. I want to show a textbox while user clicks a button.
The following code is working well in IE but not in Netscape 4.7

<!-- ---------------- -->
<html>
<head>
<title>Untitled Document</title>
</head>

<body>

<form method="post" name="frm1">
<input name="AddFiedls" type="button" value="ADD AMOUNT" onClick="AddOrHideAmount()">
<input name="HideShow" type="hidden" value="hide">

<div id="divAmt" style='display:none'>
Amount : <input name="txtAmount" type="text" value="">
</div>

</form>


</body>
</html>




<script>
function AddOrHideAmount()
{
if (document.frm1.HideShow.value == "hide")
{
document.frm1.HideShow.value = "show"
document.getElementById('divAmt').style.display="";
}
else
{
document.frm1.HideShow.value = "hide"
document.getElementById('divAmt').style.display="none";
}

}
</script>
<!-- ------------------- --->


Thanks in advance

Dubs.

gil davis
10-22-2003, 01:52 PM
NS 4.7 does not like it when you place a form object outside of a form tag. When you declare a DIV positioned, it becomes a LAYER. This takes it out of the normal document flow and creates another document (document.layers[layername].document). That is what makes the form object inside the DIV not exist inside the form tag in the topmost document.

The only way you can make this work in NS 4 is to put the complete (valid) form in the DIV.

DubsJoy
10-22-2003, 02:31 PM
Thank you for your response.

Jona
10-22-2003, 02:35 PM
Originally posted by DubsJoy
Thank you for your response.

Did Gil answer your question thoroughly, or do you need further assistance?

In case you didn't fully understand what he meant (not to take any credit away from him), simply check if getElementById() is available, if it is, use it, if it's not, check to see if document.layers is available. Again, if it is, use it.


if(document.getElementById){
&nbsp;document.getElementById("divAmt").style.display="";
}
if(document.layers){
&nbsp;document.layers["divAmt"].style.display="";
}


[J]ona

DubsJoy
10-22-2003, 03:11 PM
hi Jona,
Thanks. Does your code work...?
:confused:

Jona
10-22-2003, 03:20 PM
Take off the second "document" pat. I'll edit my code...

[J]ona

DubsJoy
10-22-2003, 03:28 PM
Still it is not working....? Can you give full programe..?

Jona
10-22-2003, 03:35 PM
I don't have NN4, so I can't test it... Sorry.

[J]ona

gil davis
10-22-2003, 04:56 PM
OK, so I read your post more carefully, and now I have a better understanding. I was jumping ahead. The reason NS 4 won't run your code is that an object must be positioned in order to access it using script. Simply using
<div id="divAmt" style='display:none'>
does not make the DIV scriptable. Now, if you use
<div id="divAmt" style='display:none; position: relative'>
then NS 4 should allow you to script the object.
document.layers["divAmt"].display = "none";
But then my original post will come into play - the form won't work.

There is yet another problem with NS 4 in that it does not treat the display property like newer browsers do. When you change an object's property to "display: none", it will only make the object invisible - it does not collapse like it does in IE or Mozilla.

Do you really have to make it work in Netscape 4?