SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast mistafeesh's Avatar
    Join Date
    Sep 2002
    Posts
    55
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    show/hide script broken!

    I have a form with a radio button which, when clicked, in theory, reveals another part of the form. It was working before, but I must've done something to it while fiddling around with other bits of the page...

    Now in it doesn't show the area at all when I click the radion button.

    the code bits are: the code at the top of the page:
    Code:
    <script language=javascript type='text/javascript'>
    <!--
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_changeProp(objName,x,theProp,theValue) { //v6.0
      var obj = MM_findObj(objName);
      if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
        if (theValue == true || theValue == false)
          eval("obj."+theProp+"="+theValue);
        else eval("obj."+theProp+"='"+theValue+"'");
      }
    }
    //-->
    </script>
    then on the form I have this code for the radio button:
    Code:
      <input name="depth" type="radio" onClick="MM_changeProp('hideShow','','style.display','visible','DIV')" value="0">Specific areas
    and this code for the layer which is shown
    Code:
    <div id="hideShow" style="display: none;">
    blahblahblah</div>
    we are all in the gutter, but some of us are looking at the stars

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    'visible' is for older browsers -- and the 'style.visibility' property.

    'block' is for newer browsers and the 'style.display' property.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    SitePoint Enthusiast mistafeesh's Avatar
    Join Date
    Sep 2002
    Posts
    55
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    sorry, I don't know enough javascript to understand that! I just 'copied' this code from another site. It was working before though, then I fiddled around with some other stuff on the page and it stopped, so I thought I must've broken it...
    we are all in the gutter, but some of us are looking at the stars

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are passing 'style.display' and 'visible'.

    the eval(...) statement -- which you shouldn't be using since it creates excess baggage -- then tries to apply 'visible' to 'display' which is wrong.

    the correct usage is:
    document.getElementById('showHide').style.display = 'block';


    PHP Code:
    <input name="depth" type="radio" onClick="doit('hideShow')" value=0>Specific areas
     
    function doit(divID)
    {
     
    document.getElementById(divID).style.display =  'block'  ;

    Where the World Once Stood
    the blades of grass
    cut me still

  5. #5
    SitePoint Enthusiast mistafeesh's Avatar
    Join Date
    Sep 2002
    Posts
    55
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    well, that's sort of fixed it. Now it works properly on IE and some other browsers, but some won't show the area at all. Namely Safari and IE on Mac OSX. People have to be able to see the area, as it's a vital part of the form, if they've clicked on a particular option. If I have to, I'll just make it permanently visible, but I'd much rather use this script.
    we are all in the gutter, but some of us are looking at the stars

  6. #6
    SitePoint Enthusiast mistafeesh's Avatar
    Join Date
    Sep 2002
    Posts
    55
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PS The old script used to work on those browsers just fine, until I broke it...can anyone tell me what I've done to it?! Would it be possible to use a combo of the two to work with all browsers?
    we are all in the gutter, but some of us are looking at the stars


Bookmarks

Posting Permissions

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