Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Simple Javascript Issue

Hello, i have a problem that probably has a simple solution but Im not too familary with javascript and cant figure it out.  I have a dynamic number of images on a page.  These images contain this href which makes a div visible:

<a href="javascript:;" onmouseover="menuLayers.show('menu1', event)" onmouseout="menuLayers.hide()">IMAGE GOES HERE</a>

The div that is made visible contains several images users can click on.  What i need to do is change the source of the image the user originally clicked on after he makes a selection from the div that pops up.  Any Ideas?

Here is my complete code:

THE IMAGE THE USER WILL CLICK, ID WILL BE UNIQUE FOR EACH ONE
<a href="javascript:;" onmouseover="menuLayers.show('menu1', event)" onmouseout="menuLayers.hide()"><img id="SearchImage1" src="Images/SearchLogos/Small/Google.jpg" style="border-width:0px;" /></a>

THE DIV THATS MADE VISIBLE
<div id="menu1" class="menu" style="position:absolute; Left: 600px; top: 50px; visibility:hidden; background-color:White;">
<div  align="center" style="width:200px; height:300px; overflow-y:scroll;">
 <div align="center"><span style="font-size: 14pt">Search Engine</span></div><br /><br />
 <img src="Images/SearchLogos/Medium/Google.jpg" onclick="javascript:toggleLayer('Google');" /><br />                
              <asp:RadioButton ID="Google" runat="server" Text="" GroupName="DefaultSearch" /><br /><br />
 <img src="Images/SearchLogos/Medium/Yahoo.jpg"  onclick="javascript:toggleLayer('Yahoo');"/><br />                
                <asp:RadioButton ID="Yahoo" runat="server" Text="" GroupName="DefaultSearch" /><br /><br />
 <img src="Images/SearchLogos/Medium/msn.jpg"  onclick="javascript:toggleLayer('MSN');"/>          
        </div>
</div>



HERE IS MY JAVASCRIPT
<script type="text/javascript">
function toggleLayer(radioButton)
{
    document.getElementById(radioButton).checked = true;
 
      this.timer = setTimeout("document.getElementById('menu1').style.visibility = 'hidden'", 200);
}



var menuLayers = {
  timer: null,
  activeMenuID: null,
  offX: 5,   // horizontal offset
  offY: -30,   // vertical offset
  show: function(id, e) {
    var mnu = document.getElementById? document.getElementById(id): null;
    if (!mnu) return;
    this.activeMenuID = id;
    if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
    if ( mnu.onmouseover == null ) mnu.onmouseover = this.clearTimer;
    viewport.getAll();
    this.position(mnu,e);
  },
 
  hide: function() {
    this.clearTimer();
    if (this.activeMenuID && document.getElementById)
      this.timer = setTimeout("document.getElementById('"+menuLayers.activeMenuID+"').style.visibility = 'hidden'", 200);
  },
 
  position: function(mnu, e) {
    var x = e.pageX? e.pageX: e.clientX + viewport.scrollX;
    var y = e.pageY? e.pageY: e.clientY + viewport.scrollY;
   
    if ( x + mnu.offsetWidth + this.offX > viewport.width + viewport.scrollX )
      x = x - mnu.offsetWidth - this.offX;
    else x = x + this.offX;
 
    if ( y + mnu.offsetHeight + this.offY > viewport.height + viewport.scrollY )
      y = ( y - mnu.offsetHeight - this.offY > viewport.scrollY )? y - mnu.offsetHeight - this.offY : viewport.height + viewport.scrollY - mnu.offsetHeight;
    else y = y + this.offY;
   
    mnu.style.left = x + "px"; mnu.style.top = y + "px";
    this.timer = setTimeout("document.getElementById('" + menuLayers.activeMenuID + "').style.visibility = 'visible'", 200);
  },
 
  mouseoutCheck: function(e) {
    e = e? e: window.event;
    // is element moused into contained by menu? or is it menu (ul or li or a to menu div)?
    var mnu = document.getElementById(menuLayers.activeMenuID);
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( mnu != toEl && !menuLayers.contained(toEl, mnu) ) menuLayers.hide();
  },
 
  // returns true of oNode is contained by oCont (container)
  contained: function(oNode, oCont) {
    if (!oNode) return; // in case alt-tab away while hovering (prevent error)
    while ( oNode = oNode.parentNode )
      if ( oNode == oCont ) return true;
    return false;
  },

  clearTimer: function() {
    if (menuLayers.timer) clearTimeout(menuLayers.timer);
  }
 
}
</script>


THANKS VERY MUCH!!
0
grogo21
Asked:
grogo21
1 Solution
 
ahoffmannCommented:
<asp:RadioButton

is not a valid HTML tag, hence the assigned attributes with the function cll will most likely not executed
0
 
grogo21Author Commented:
Any ideas on how i can pass the id of the image the user clicked to then change that image after another election is made?  Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now