Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorMKayHavoc
    • CommentTimeDec 29th 2007
     permalink

    I've written an onload function that cycles through div's that have a class of sub_subslide bar. Stripped down HTML looks like this:


    <form action="#" method="post"><input type="hidden" name="phpMyAdmin" value="4594f30712f4fabaff6997416810f3f2" />
    <div id="submitNews">
    <fieldset class="newsForm"><input type="hidden" name="phpMyAdmin" value="4594f30712f4fabaff6997416810f3f2" />
    ... Form Fields ...
    </fieldset>
    <div><div class="sub_slidebar"></div></div> <!--Wrapper to fix crap IE bug-->
    </div>
    </form>

    Basic idea is I have a submissions page with any number of forms, that are expandable onclick. So I need a function that it flexible and doesn't need to be tied to a specific ID.


    The javaScript function is this:


    function slidebarPrep(){
    if(!document.getElementById) return false;
    var slidebar = document.getElementsByTagName("div");
    for(var i = 0; i < slidebar.length; i++){
    if(slidebar[i].className == "sub_slidebar"){
    var parentId = slidebar[i].offsetParent.id;
    var parentHeight = slidebar[i].offsetParent.clientHeight;

    var subBox = document.getElementById(parentId);

    subBox.style.height = "115px";
    slidebar[i].setAttribute("onclick", "sub_expand(50, '"+parentId+"', '"+parentHeight+"');");
    }
    }
    }

    It works perfectly in FF but not in IE. The issue with with the setAttribute for onclick. Everything i've tried doesn't fix it. I've tried attachEvent for to see if that works for IE and it doesn't. I've also tried this:


    slidebar[i].onclick = function(){
    sub_expand(50, parentId, parentHeight);
    }

    But this generates some very strange behaviour in both FF and IE.


    Does anyone have any suggestions?

  1.  permalink
    Hi MKayHavoc,

    This is unfortunately a known bug in all versions of IE. There are SEVERAL things you can't set in IE using .setAttribute()

    A list (with some workarounds) is provided with the bug report here:
    http://webbugtrack.blogspot.com/2007/08/bug-242-setattribute-doesnt-always-work.html
    • CommentAuthorFLEB
    • CommentTimeFeb 10th 2008
     permalink
    Why not just use slidebar[i].onclick = ...?
Add your comments
    Username Password
  • Format comments as (Help)