SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jun 2006
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Basic Function help

    Hi Folks,

    I'm having some trouble with a function I call then an option is selected in my list, can anyone help? I can seem to get the if statement to work, and hide/ show the appropriate div.

    Thankyou

    Code:
    function getrooms(){
    
    for (optioncounter = 0; optioncounter < document.avform.campus_select.length; optioncounter ++)
    {
    var el = document.getElementById('e'+optioncounter).style;
    
    
    if(document.avform.campus_select.options[optioncounter].value != document.avform.campus_select.selectedIndex)
    {
    el.display == "none";
    
    }else{
    el.display == "block";alert(el.display);
    }
    
    }
    }
    
    <select name="campus_select" onChange="getrooms();">
    <option value="1">Whittingham</option>
    <option value="2">Shenstone</option>
    <option value="3">CW</option>
    </select>
    
    <div id="e0" style="display:none;">0</div>
    <div id="e1" style="display:none;">1</div> <div id="e2" style="display:none;">2</div>

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) That's an interesting way to do it.

    You seem to be missing one important detail, however. In JavaScript arrays start with index 0, so either the values of the options need to start at 0 or you need to compensate for that in the function.

    2) I suggest you read these:
    Optimizing JavaScript for Execution Speed
    DHTML and JavaScript Performance Tuning

    3) Keep in mind that some Internet users use a browser that doesn't have JavaScript enabled.

    I suggest you read these:
    You cannot rely on JavaScript being available. Period.
    Graded Browser Support
    Progressive Enhancement and the Future of Web Design
    Accessibility is seldom just up to the interface developer
    XMLHttpRequest Usability Guidelines
    "This is not another XMLHttpRequest article"
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •