Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    USA, East Coast
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question stumper: thread fighting? how does JavaScript compile and run code segments?

    Oddly, when I remove the alert statements from this code, i will get flickering lists. But having the alert box makes the selection all happen when the form is hidden.

    I am using setTimeout to allow the function to end so that it will execute the code to change the form after the code to hide the form is run.

    otherwise it seems like its a random occurance of how the selecting of items in the list will happen.

    The following code should run

    removing the setTimeouts works, but removing both the alerts and setTimeouts causes fighting to occur.

    Any ideas? or ways I can do this without using the setTimeouts?

    Code:
    <html>
    <head>
    <script>
    function set_check() {
    
    alert("Debug: now running the check function");
    
    if (document.layers) {
      check_field = document.form_layer.document.frmExample.chkAll;
      select_field = document.form_layer.document.frmExample.list;
    } else {
      check_field = document.frmExample.chkAll;
      select_field = document.frmExample.list;
    }
     
      if (check_field.checked == false) {
        for (i=0;i<select_field.length;i++) {
          select_field[i].selected = false;
        }
    
        select_field.selectedIndex = -1;
      } else if (check_field.checked == true) {
        for (i=0;i<select_field.length;i++) {
          if (i != select_field.length - 1) {
            select_field[i].selected = true;
          } else {
            // coding to not select the NULL_SPACER
            select_field[i].selected = false;            
          }
        }
      }
    }
    
    function toggle_layer_visibility( layer_to_change ) {
      if ((layer_to_change != null) && (layer_to_change != "")) {
        if (document.layers) { 
          if (document.layers[layer_to_change].visibility == 'visible' || document.layers[layer_to_change].visibility == 'show') {
            alert("Debug: Toggle Layer  (HIDE)"); 
            document.layers[layer_to_change].visibility = 'hidden';
          } else if (document.layers[layer_to_change].visibility == 'hidden' || document.layers[layer_to_change].visibility == 'hide') {
            alert("Debug: Toggle Layer  (SHOW)"); 
            document.layers[layer_to_change].visibility = 'visible';
          }
    
        } else if (document.all) {
    
          if (document.all[layer_to_change].style.visibility == 'visible') {
            alert("Debug: Toggle Layer  (HIDE)"); 
            document.all[layer_to_change].style.visibility = 'hidden';
          } else if (document.all[layer_to_change].style.visibility == 'hidden') {
            alert("Debug: Toggle Layer  (SHOW)"); 
            document.all[layer_to_change].style.visibility = 'visible';
          } 
        }
    
      } else {
        alert('Nothing was sent to the layer_toggle_visibility function');
      }
    }
    
    //
    // Done to allow IE to see a visible property.
    //
    function init_layer() {
      if (document.all) {
        document.all['form_layer'].style.visibility = "visible";
      }
    }
    
    </script>
      <style type="text/css">
        #form_layer {
                      visibility: visible;
                      z-index: 20;
                      position: absolute;
                      top: 45px;
                      left: 135px;
                      width: 650px; 
                      height: 410px;
                    }
      </style>
    </head>
    <body onload="init_layer();">
    This is a demonstration of doing work on a hidden form.
    <div id="form_layer">
      <form name="frmExample" action="javascript:void(0);" method="POST"> 
        The list<br>  
        <select name="list" multiple size="7">
          <option>the one</option>
          <option>the second</option>
          <option>the third</option>
          <option>the fourth</option>
          <option>the fifth</option>
          <option>the one</option>
          <option>the second</option>
          <option>the third</option>
          <option>the fourth</option>
          <option>the fifth</option>
          <option>the one</option>
          <option>the second</option>
          <option>the third</option>
          <option>the fourth</option>
          <option>the fifth</option>
          <option>the one</option>
          <option>the second</option>
          <option>the third</option>
          <option>the fourth</option>
          <option>the fifth</option>
          <option>the one</option>
          <option>the second</option>
          <option>the third</option>
          <option>the fourth</option>
          <option>the fifth</option>
          <option>the one</option>
          <option>the second</option>
          <option>the third</option>
          <option>the fourth</option>
          <option>the fifth</option>
          <option>____________________</option>    
        </select>
        <br><br>
        <input type="checkbox" name="chkAll" value="FALSE" onclick="toggle_layer_visibility('form_layer');setTimeout('set_check();', 1);setTimeout('toggle_layer_visibility(\'form_layer\');', 10);">
        click to select all items in the list.
      </form>
    </div>
    </body>
    </html>

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    USA, East Coast
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy I am going to conclude this is one of those quarks...

    no ideas?

    man....

    -S. Bob


  •  

    Posting Permissions

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