...

View Full Version : Show/Hide Div?



doni
03-19-2006, 06:42 PM
I've got a form defined inside a DIV. When the page first loads this DIV is hidden and then when a particular button is clicked, the div (and more importantly the form) is supposed to be shown. But when the button is clicked the div doesn't show up.

This is the code I'm using to try and show the div (it's part of a function that runs with an onclick event from one of my buttons--I've confirmed that function IS running when I click the button):


document.getElementById("frm").style.display="block";


This is the XHTML code that builds my div:


<div name="frm" style="display:none"><br>Hello!<br><form name="f1"><table>
<tr><td colspan="3">Click on an item in either field list to see the purpose/meaning of each.</td></tr>
<!-- <tr><td><input type="textarea" name="t1"</td></tr> -->
<tr>
<td valign="top">
<select name=IdxAvailable size="10" onchange="changetext(fldNames[this.options[this.selectedIndex].value])">
<!-- javascript function will build this select list -->
</select>
</td>
<td valign="center">
<input type="button" onclick="addItem()" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add >&nbsp;&nbsp;&nbsp;&nbsp;"><br>
<input type="button" value="< Remove" onclick="removeItem()">

</td>
<td valign="top">
<select name="IdxUsed" size="9" onchange="changetext(fldNames[this.options[this.selectedIndex].value])"> -->
<!-- javascript function will build this select list -->
</select><br>
<input type="button" value="Move Up" name="MoveUp" onclick="moveUp()"><input type="button" value="MoveDn" name="Move Down" onclick="moveDn()">
</td>
<td>&nbsp;</td>
<td width="500" valign="top">
<ilayer id="d1" width="200" height="200" visibility="hide">
<layer id="d2" width="200" height="200">
<div id="descriptions" align="left">

<!-- javascript function add text here -->

</div>
</layer>
</ilayer>
</td>
</tr>
<tr>
</tr>
</table></form> </div>

Kravvitz
03-20-2006, 01:19 AM
NAMEs and IDs are not the same.

Change

<div name="frm"
to

<div id="frm"

Why are you using <layer> and <ilayer> elements? Only NS4.x supports them.

doni
03-20-2006, 03:28 AM
NAMEs and IDs are not the same.

Change

<div name="frm"
to

<div id="frm"

Thanks! I knew it was probably something simple but I just wasn't picking up on it.



Why are you using <layer> and <ilayer> elements? Only NS4.x supports them.
An example script that I found on DynamicDrive showed that. That script adds/changes text in this DIV. I think that was to deal with cross-browser compatibility issues.

doni
03-20-2006, 05:07 AM
Well I changed the code as follows and it's still not displaying :confused: :


function upDtLists(itm){
var avaiList = document.f1.IdxAvailable;
var usedList = document.f1.IdxUsed;
var txt2 = itm.name.split("^");
itm.enabled = false;
txt = txt2[1];
//f1.fldSets.options[f1.fldSets.selectedIndex].value;
alert (txt2[0]); // <--When this function runs, I DO see the alert box.
document.getElementById("frm").style.display=block;
var j = 0;
var used = txt.split(",");
avaiList.options.length = 0;
usedList.options.length = 0;
for (k = 0; k < buttonList.length; k++){
//buttonList
}
for (k=0;k < fields.length; k++){
j = 0
for (i=0;i < used.length;i++){
if(k==i){
j = 1
usedList.options[usedList.options.length] = new Option(fields[k], k);
}
}
if(j == 0){
avaiList.options[avaiList.options.length] = new Option(fields[k], k);
}
}
}




<div id="frm" style="display:none"><br>Hello!<br><form name="f1"><table>
<tr><td colspan="3">Click on an item in either field list to see the purpose/meaning of each.</td></tr>
<!-- <tr><td><input type="textarea" name="t1"</td></tr> -->
<tr>
<td valign="top">
<select name=IdxAvailable size="10" onchange="changetext(fldNames[this.options[this.selectedIndex].value])">
<!-- javascript function will build this select list -->
</select>

</td>
<td valign="center">
<input type="button" onclick="addItem()" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add >&nbsp;&nbsp;&nbsp;&nbsp;"><br>
<!-- javascript function will build this select list -->
<input type="button" value="< Remove" onclick="removeItem()">

</td>
<td valign="top">
<select name="IdxUsed" size="9" onchange="changetext(fldNames[this.options[this.selectedIndex].value])"> -->
<!-- javascript function will build this select list -->

</select><br>
<input type="button" value="Move Up" name="MoveUp" onclick="moveUp()"><input type="button" value="MoveDn" name="Move Down" onclick="moveDn()">
</td>
<td>&nbsp;</td>
<td width="500" valign="top">
<ilayer id="d1" width="200" height="200" visibility="hide">
<layer id="d2" width="200" height="200">
<div id="descriptions" align="left">

<!-- javascript function add text here -->

</div>
</layer>
</ilayer>
</td>
</tr>
<tr>
</tr>

</table></form> </div>

jscheuer1
03-20-2006, 05:15 AM
You could have other problems but this:


document.getElementById("frm").style.display=block;

needs to be:


document.getElementById("frm").style.display='block';

Block is a literal, not a variable.

doni
03-20-2006, 05:17 AM
Thx for the FAST reply!

I used to have double quotes around it--but that wasn't working, so I took them off. I'll try single quotes.

Kravvitz
03-20-2006, 05:20 AM
If that doesn't fix it, you'll need to post more of your code.

doni
03-20-2006, 05:25 AM
Twas it!

Thanks. Well I guess it needed the SINGLE quotes as opposed to the double quotes.

jscheuer1
03-20-2006, 05:31 AM
Hate to burst your bubble but, single quotes or double quotes are the same thing in this particular situation. Perhaps, back when you had the double quotes, there was another problem(s).

mlanka
04-11-2006, 12:23 PM
try the function below, i wrote it a while back ago and i've tested it on ie and firefox(works fine)
in your css use the visibility:hidden;
onClick(func_handleDiv('div_id',1));
that should work.....



function func_handleDiv(div,status){

var obj_i = div;
var obj_s = status;

if(obj_s == 1){
obj_s = "visible";
}else{
obj_s = "hidden";
}

if(document.all)
{
document.getElementById(obj_i).style.visibility = obj_s;
}else if(document.getElementById)
{
document.getElementById(obj_i).style.visibility = obj_s;
}
}

wbmdan
05-04-2006, 02:38 AM
try the function below, i wrote it a while back ago and i've tested it on ie and firefox(works fine)
in your css use the visibility:hidden;
onClick(func_handleDiv('div_id',1));
that should work.....



function func_handleDiv(div,status){

var obj_i = div;
var obj_s = status;

if(obj_s == 1){
obj_s = "visible";
}else{
obj_s = "hidden";
}

if(document.all)
{
document.getElementById(obj_i).style.visibility = obj_s;
}else if(document.getElementById)
{
document.getElementById(obj_i).style.visibility = obj_s;
}
}



Hi mlanka,

I'm new to the form...I would like to try working with your script and have a question about the JavaScript below:

onClick(func_handleDiv('div_id',1));

How do I set this up as a link?

I would like to be able to say something like "click here for this" and then the hidden area will be displayed.

Looking forward to your reply.

Thank you.

Daniel



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum