Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2006, 05:42 PM   PM User | #1
doni
Regular Coder

 
Join Date: Oct 2002
Posts: 178
Thanks: 3
Thanked 0 Times in 0 Posts
doni is an unknown quantity at this point
Show/Hide Div?

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):
Code:
        document.getElementById("frm").style.display="block";
This is the XHTML code that builds my div:
Code:
<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>

Last edited by doni; 03-19-2006 at 05:59 PM..
doni is offline   Reply With Quote
Old 03-20-2006, 12:19 AM   PM User | #2
Kravvitz
Senior Coder

 
Join Date: Feb 2006
Location: USA
Posts: 1,013
Thanks: 0
Thanked 0 Times in 0 Posts
Kravvitz is an unknown quantity at this point
NAMEs and IDs are not the same.

Change
Code:
<div name="frm"
to
Code:
<div id="frm"
Why are you using <layer> and <ilayer> elements? Only NS4.x supports them.
__________________
Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
Java != JavaScript && JScript != JavaScript
Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.
Kravvitz is offline   Reply With Quote
Old 03-20-2006, 02:28 AM   PM User | #3
doni
Regular Coder

 
Join Date: Oct 2002
Posts: 178
Thanks: 3
Thanked 0 Times in 0 Posts
doni is an unknown quantity at this point
Quote:
Originally Posted by Kravvitz
NAMEs and IDs are not the same.

Change
Code:
<div name="frm"
to
Code:
<div id="frm"
Thanks! I knew it was probably something simple but I just wasn't picking up on it.

Quote:
Originally Posted by Kravvitz
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 is offline   Reply With Quote
Old 03-20-2006, 04:07 AM   PM User | #4
doni
Regular Coder

 
Join Date: Oct 2002
Posts: 178
Thanks: 3
Thanked 0 Times in 0 Posts
doni is an unknown quantity at this point
Well I changed the code as follows and it's still not displaying :
Code:
        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);
            }
        }
}
Code:
<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>

Last edited by doni; 03-20-2006 at 04:09 AM..
doni is offline   Reply With Quote
Old 03-20-2006, 04:15 AM   PM User | #5
jscheuer1
Regular Coder

 
Join Date: Mar 2005
Location: SE PA USA
Posts: 373
Thanks: 0
Thanked 0 Times in 0 Posts
jscheuer1 is an unknown quantity at this point
You could have other problems but this:

Code:
document.getElementById("frm").style.display=block;
needs to be:

Code:
document.getElementById("frm").style.display='block';
Block is a literal, not a variable.
__________________
- John
jscheuer1 is offline   Reply With Quote
Old 03-20-2006, 04:17 AM   PM User | #6
doni
Regular Coder

 
Join Date: Oct 2002
Posts: 178
Thanks: 3
Thanked 0 Times in 0 Posts
doni is an unknown quantity at this point
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.
doni is offline   Reply With Quote
Old 03-20-2006, 04:20 AM   PM User | #7
Kravvitz
Senior Coder

 
Join Date: Feb 2006
Location: USA
Posts: 1,013
Thanks: 0
Thanked 0 Times in 0 Posts
Kravvitz is an unknown quantity at this point
If that doesn't fix it, you'll need to post more of your code.
__________________
Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
Java != JavaScript && JScript != JavaScript
Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.
Kravvitz is offline   Reply With Quote
Old 03-20-2006, 04:25 AM   PM User | #8
doni
Regular Coder

 
Join Date: Oct 2002
Posts: 178
Thanks: 3
Thanked 0 Times in 0 Posts
doni is an unknown quantity at this point
Twas it!

Thanks. Well I guess it needed the SINGLE quotes as opposed to the double quotes.
doni is offline   Reply With Quote
Old 03-20-2006, 04:31 AM   PM User | #9
jscheuer1
Regular Coder

 
Join Date: Mar 2005
Location: SE PA USA
Posts: 373
Thanks: 0
Thanked 0 Times in 0 Posts
jscheuer1 is an unknown quantity at this point
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).
__________________
- John
jscheuer1 is offline   Reply With Quote
Old 04-11-2006, 11:23 AM   PM User | #10
mlanka
New to the CF scene

 
Join Date: Apr 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
mlanka is an unknown quantity at this point
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.....

Code:
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;
	}
}
mlanka is offline   Reply With Quote
Old 05-04-2006, 01:38 AM   PM User | #11
wbmdan
New to the CF scene

 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
wbmdan is an unknown quantity at this point
Question Link Question - Related to JavaScript Code Below

Quote:
Originally Posted by mlanka
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.....

Code:
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
wbmdan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:13 AM.


Advertisement
Log in to turn off these ads.