View Full Version : Showing a Layer at the position of a SPAN ID

09-15-2010, 08:10 PM
I have the javascript below which toggles a LAYER on my page to show and hide.

I need to revise it to do 2 things:

1. don't hide it anymore upon toggle. Only show and keep showing whenever running.
2. Have the Layer pop up or display INLINE exactly where the user clicks the span id that triggers the javascript as opposed to wherever the layer resides on the page. I can't move the layer to where the link is.

<script type="text/javascript">
function toggleLayeraddwordcomment( whichLayer, wordnumber, sbid )
var elem, vis;
if( document.getElementById ) // this is the way the standards work
elem = document.getElementById( whichLayer );
else if( document.all ) // this is the way old msie versions work
elem = document.all[whichLayer];
else if( document.layers ) // this is the way nn4 works
elem = document.layers[whichLayer];
vis = elem.style;
document.getElementById('txtwordnumber').value = wordnumber
// if the style.display value is blank we try to figure it out here
vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
vis.display = (vis.display==''||vis.display=='block')?'none':'block';

<span id="spanid" ondblclick=toggleLayer('addcomment,'1','2');"></span>

<div id="addcomment" style="display:none;padding:10px 10px 10px 10px;background-color:#CCCCCC;"><input name="txtwordnumber" type="text" id="txtwordnumber" value="" size="1" disabled/><input name="wordcommentinput" type="text" size="50" maxlength="250" />

09-15-2010, 11:26 PM

I'm now using this Javascript to show a layer.

All I'm trying to do now is have it show the layer wherever the cursor is as opposed to where the layer is actually located.

<script language="javascript">
var state = 'none';

function showaddwordcomment(layer_ref,wordnumber,sbid) {
document.getElementById('txtwordnumber' + sbid).value = wordnumber;
if (state == 'none') {
state = 'block';
else {
state = 'block';
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.display = state");
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].display = state;
if (document.getElementById &&!document.all) {
hza = document.getElementById(layer_ref);
hza.style.display = state;