Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: Show/Hide Div?

  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Posts
    178
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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 06:59 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Posts
    178
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Oct 2002
    Posts
    178
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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 05:09 AM.

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder
    Join Date
    Oct 2002
    Posts
    178
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Regular Coder
    Join Date
    Oct 2002
    Posts
    178
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Twas it!

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

  • #9
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #10
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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;
    	}
    }

  • #11
    New to the CF scene
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •