Results 1 to 4 of 4

Thread: positioning problem

  1. #1

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    positioning problem

    This is my sample at it's basic, what I'd like to do using javascript
    is to add a picture into a table cell. I.e. the table cell acting as a
    container for the picture when a button is clicked.

    Can anyone help me with this please?

    Code:
    <HTML>
    <HEAD>
    
    	<SCRIPT Language=javascript>
    
    	function buttonclicked()
    	{
    
    	}
    
    	</script>
    
    </HEAD>
    
    <BODY>
    
    	<IMG id=img1 Style="Position:Absolute" Src="1.bmp">
    
    	<BR><BR><BR>
    
    	<TABLE id=tbl1 border=1>
    	<TR id=Row1>
    		<TD width=100px height=100px id=Cell1>
    	</TR>
    	</TABLE>
    
    	<BR><BR><BR>
    
    	<INPUT Type=button onclick=buttonclicked() value="click here!">
    
    </BODY>
    </HTML>

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    take ur pick... personally, i prefer number 2

    (1)
    Code:
    <HTML>
    <HEAD>
    
    	<SCRIPT Language=javascript>
    
    	function buttonclicked(cellId)
    	{
    		var cellParent;
    
            if (document.all) {
    			cellParent = document.all[cellId];
            }
            	
            if (!document.all && document.getElementById) {
    			cellParent = document.getElementById(cellId);
            }
            
    		if (cellParent.innerHTML == ""){		
    		   cellParent.innerHTML = "<img id='img1' src='gfx/blue_chevron_down.gif'>";
    		} else {
    		   cellParent.innerHTML = "";
    		}
    	}
    
    	</script>
    
    </HEAD>
    
    <BODY>
    
    	<BR><BR><BR>
    	<TABLE id=tbl1 border=1>
    	<TR id=Row1>
    		<TD width=100px height=100px id="Cell_1">
    			
    		</TD>
    	</TR>
    	</TABLE>
    
    	<BR><BR><BR>
    
    	<INPUT Type=button onclick=buttonclicked("Cell_1") value="click here!">
    
    </BODY>
    </HTML>


    or.....


    (2)

    Code:
    <HTML>
    <HEAD>
    
    	<SCRIPT Language=javascript>
    
    	function buttonclicked(imgId)
    	{
    		var cellParent, item;
    		var displayItem = "inline";
    		var hiddenItem = "none";
    
            if (document.all) {
    			item = document.all[imgId];
            }
            	
            if (!document.all && document.getElementById) {
    			item = document.getElementById(imgId);
            }
    		
    		if (item.style.display == displayItem) {
    		    item.style.display = hiddenItem;
    		} else {
    		  	item.style.display = displayItem;
    		}        
    	}
    
    	</script>
    
    </HEAD>
    
    <BODY>
    
    	<BR><BR><BR>
    	<TABLE id="tbl1" border="1">
    	<TR id=Row1>
    		<TD width=100px height=100px id="Cell_1">
    			<img id="img1" src="gfx/blue_chevron_down.gif" style="display:none" >
    		</TD>
    	</TR>
    	</TABLE>
    
    	<BR><BR><BR>
    
    	<INPUT Type=button onclick=buttonclicked("img1") value="click here!">
    </BODY>
    </HTML>

  3. #3

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Fantastic, that's helped me a great deal thanks!
    BTW - love the Garfield avatar! ;c)

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    you're welcome & i thought it was rather good too...

Posting Permissions

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



Click Here to Expand Forum to Full Width