3.2.0

more than one element same id?

Im trying to make this code work. 2 problems. first is it wont record position in IE, second problem is adding more elements 9images0 to make them work also. any help appreciated, TIA

<script type="text/javascript">

function setCookie(cookieName,cookieValue,cookieExpiration) {
    
    if (cookieExpiration!=null) {

        document.cookie=cookieName + "=" + escape(cookieValue) + ";path=/;expires=" + cookieExpiration.toGMTString()
    } else {
       session
        document.cookie=cookieName + "=" + escape(cookieValue) + ";path=/"
    }
}

// Get cookie value
function getCookie(cookieName) { 

    cookieString=document.cookie
    cookieName+="="
    
    
    if (cookieString.length>0) {
        

        i=cookieString.indexOf(cookieName)
        
        
        if (i!=-1) {
            i += cookieName.length
            j = cookieString.indexOf(";",i)
            
            if (j==-1) {j = cookieString.length}
            
            return unescape(cookieString.substring(i,j))
        }
    }


    return null
}


function deleteCookie(cookieName) {
    

    cookieExpiration = new Date(2009,0,1)
    
    document.cookie=cookieName + "=;path=/;expires=" + cookieExpiration.toGMTString()
}


function getAbsLeft(o) {
    oLeft = o.offsetLeft
    while(o.offsetParent!=null) {
        oParent = o.offsetParent
        oLeft += oParent.offsetLeft
        o = oParent
    }
    return oLeft
}


function getAbsTop(o) {
    oTop = o.offsetTop
    while(o.offsetParent!=null) {
        oParent = o.offsetParent
        oTop += oParent.offsetTop
        o = oParent
    }
    return oTop
}


function setLeft(o,oLeft) {
    o.style.left = oLeft + "px"
}

function setTop(o,oTop) {
    o.style.top = oTop + "px"
}

function setPosition(o,oLeft,oTop) {
    setLeft(o,oLeft)
    setTop(o,oTop)
}


function dragMouseDown(e)
{
    
    if (!e) {e = window.event}
    
    
    doDrag=true
    
    
    o=document.getElementById("draggedObjects")
    

    oLeft=getAbsLeft(o)
    oTop=getAbsTop(o)
    

    mouseLeft=e.clientX-oLeft
    mouseTop=e.clientY-oTop
    
}


function dragMouseUp(e)
{
    
    doDrag=false

    
    if (!e) {e = window.event}
    
    

    oLeft = e.clientX-mouseLeft
    oTop = e.clientY-mouseTop
    cookieValue = "var oLeft=" + oLeft + ";" + "var oTop=" + oTop
    setCookie("recPos",cookieValue,expirationDate)

}


function dragMouseMove(e)
{
    
    if (!e) {e = window.event}
    

    if (doDrag)
    {
        
        o=document.getElementById("draggedObjects")
        
    
        oLeft = e.clientX-mouseLeft
        oTop = e.clientY-mouseTop
        setPosition(o,oLeft,oTop)
        
        
        return false
    }	
}


function getRecPos()
{
    alert(getCookie("recPos"))
}


function setRecPos()
{
    cookieValue = getCookie("recPos")
    if (cookieValue!=null)
    {

        eval(cookieValue)
        

        o=document.getElementById("draggedObjects")
        setPosition(o,oLeft,oTop)
    }
}


expirationDate = new Date()
expirationDate.setDate(expirationDate.getDate() + 10)

doDrag=false
mouseLeft=0
mouseTop=0

document.onmousemove = dragMouseMove
</script>



<body onload="setRecPos()">
<div id="draggedObjects" style="position:absolute;top:460px;left:100px;cursor:pointer;cursor:hand;" onmousedown="dragMouseDown(event)" onmouseup="dragMouseUp(event)"><img src="http://i14.photobucket.com/albums/a345/Instar/RedFlag.gif">
</div>

</body>
CH
April 19,

This topic is archived.

See also:


Back to support forum