ie 8 loop

  • Kurthead+1
  • Graduate
  • Graduate
  • Kurthead+1
  • Posts: 131

Post 3+ Months Ago

Is there any specific reason this shouldn't work in IE8? Because it works in all other browsers. Says that the clear1 array is undefined, which it is.

JAVASCRIPT Code: [ Select ]
      for(z=0;z<=clear1.length;z++)
        {
       clear1[z].checked = false;
             }
       
 
  1.       for(z=0;z<=clear1.length;z++)
  2.         {
  3.        clear1[z].checked = false;
  4.              }
  5.        
  6.  


I've tried defining it both ways
JAVASCRIPT Code: [ Select ]
clear1 = new Array(a,b,c,d,e,f,g,h,i,j,k,l,m,n);
clear1 = [a,b,c,d,e,f,g,h,i,j,k,l,m,n];
 
  1. clear1 = new Array(a,b,c,d,e,f,g,h,i,j,k,l,m,n);
  2. clear1 = [a,b,c,d,e,f,g,h,i,j,k,l,m,n];
  3.  

Those letters are variables by the way.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

It seems to me that you are doing check boxes, correct? If this is true can you post the full code?
  • Kurthead+1
  • Graduate
  • Graduate
  • Kurthead+1
  • Posts: 131

Post 3+ Months Ago

It's radio boxes, but yes, same idea. It works in all other browsers, and the only way I've found to make it work in IE8 (& lower) is to set them individually rather than in a loop.

The radio select is for a Private Investigation firm, specializing in sexual crimes, so disregard the element id's lol. I think the error I was getting was that the array is undefined.
JAVASCRIPT Code: [ Select ]
function optSelectAll()
   {
   a = document.getElementById('cheat');
   b = document.getElementById('abuse');
   c = document.getElementById('disabled');
   d = document.getElementById('illegal');
   e = document.getElementById('exploit');
   f = document.getElementById('traffick');
   g = document.getElementById('cp');
   h = document.getElementById('cold');
   i = document.getElementById('rc');
   j = document.getElementById('missing');
   k = document.getElementById('track');
   l = document.getElementById('serial');
   m = document.getElementById('other');
   n = document.getElementById('stalk');
   o = document.getElementById('specify');
   clear1 = new Array(a,b,c,d,e,f,g,h,i,j,k,l,m,n);
      for(z=0;z<=clear1.length;z++)
        {
       clear1[z].checked = false;
       }
       
     if (clear1[12].checked == false)
        {
       o.style.visibility="hidden";
       }
   }
 
  1. function optSelectAll()
  2.    {
  3.    a = document.getElementById('cheat');
  4.    b = document.getElementById('abuse');
  5.    c = document.getElementById('disabled');
  6.    d = document.getElementById('illegal');
  7.    e = document.getElementById('exploit');
  8.    f = document.getElementById('traffick');
  9.    g = document.getElementById('cp');
  10.    h = document.getElementById('cold');
  11.    i = document.getElementById('rc');
  12.    j = document.getElementById('missing');
  13.    k = document.getElementById('track');
  14.    l = document.getElementById('serial');
  15.    m = document.getElementById('other');
  16.    n = document.getElementById('stalk');
  17.    o = document.getElementById('specify');
  18.    clear1 = new Array(a,b,c,d,e,f,g,h,i,j,k,l,m,n);
  19.       for(z=0;z<=clear1.length;z++)
  20.         {
  21.        clear1[z].checked = false;
  22.        }
  23.        
  24.      if (clear1[12].checked == false)
  25.         {
  26.        o.style.visibility="hidden";
  27.        }
  28.    }
  29.  


Here's the html

Code: [ Select ]
            <div id="inquery" class="radio1">
              <div class="radio1">
               <div class="float1"><p id="fon">domestic/ cheating spouse</p></div>
                 <div class="float2"><input class="align" style="float:left;" type="radio" value="cheat" name="cheat" onmouseup="clearText();" id="cheat" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>sexual abuse, or harrassment in the work place</p></div>
                 <div class="float2"><input type="radio" value="abuse" name="abuse" id="abuse" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>workers comp – disabled person working as exotic dancer, escort, masseuse, etc.</p></div>
                 <div class="float2"><input type="radio" value="disabled" name="disabled" id="disabled" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>illegal activities (prostitution, gambling, underage trafficking, etc) in strip clubs, massage parlors</p></div>
               <div class="float2"><input type="radio" value="illegal" name="illegal" id="illegal" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>illegal immigrant sexual exploitation</p></div>
                 <div class="float2"><input type="radio" value="exploit" name="exploit" id="exploit" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>illegal human sex trafficking</p></div>
                 <div class="float2"><input type="radio" value="traffick" name="traffick" id="traffick" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>child pornography ring</p></div>
                 <div class="float2"><input type="radio" value="cp" name="cp" id="cp" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>cold case work involving sex crimes</p></div>
                 <div class="float2"><input type="radio" value="cold" name="cold" id="cold" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>rape case investigations</p></div>
                 <div class="float2"><input type="radio" value="rc" name="rc" id="rc" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>missing, kidnapped or exploited children</p></div>
                 <div class="float2"><input type="radio" value="missing" name="missing" id="missing" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>tracking sex offenders</p></div>
                 <div class="float2"><input type="radio" value="track" name="track" id="track" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>stalking and sexual obsessions</p></div>
                 <div class="float2"><input type="radio" value="stalk" name="stalk" id="stalk" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>serial sex murders</p></div>
                 <div class="float2"><input type="radio" value="serial" name="serial" id="serial" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
                 <div class="float1"><p>other</p></div>
                 <div class="float2"><input type="radio" value="other" name="other" id="other" onmousedown="optSelectAll();" onclick="openText();"></div>
                 <div class="float1"><textarea name="specify" id="specify" value="Specify other (200 characters max)" maxlength="200"></textarea></div>
              </div>
        </div>
  1.             <div id="inquery" class="radio1">
  2.               <div class="radio1">
  3.                <div class="float1"><p id="fon">domestic/ cheating spouse</p></div>
  4.                  <div class="float2"><input class="align" style="float:left;" type="radio" value="cheat" name="cheat" onmouseup="clearText();" id="cheat" onmousedown="optSelectAll();" onclick=""></div>
  5.                  <div class="float1"><p>sexual abuse, or harrassment in the work place</p></div>
  6.                  <div class="float2"><input type="radio" value="abuse" name="abuse" id="abuse" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  7.                  <div class="float1"><p>workers comp – disabled person working as exotic dancer, escort, masseuse, etc.</p></div>
  8.                  <div class="float2"><input type="radio" value="disabled" name="disabled" id="disabled" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  9.                  <div class="float1"><p>illegal activities (prostitution, gambling, underage trafficking, etc) in strip clubs, massage parlors</p></div>
  10.                <div class="float2"><input type="radio" value="illegal" name="illegal" id="illegal" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  11.                  <div class="float1"><p>illegal immigrant sexual exploitation</p></div>
  12.                  <div class="float2"><input type="radio" value="exploit" name="exploit" id="exploit" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  13.                  <div class="float1"><p>illegal human sex trafficking</p></div>
  14.                  <div class="float2"><input type="radio" value="traffick" name="traffick" id="traffick" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  15.                  <div class="float1"><p>child pornography ring</p></div>
  16.                  <div class="float2"><input type="radio" value="cp" name="cp" id="cp" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  17.                  <div class="float1"><p>cold case work involving sex crimes</p></div>
  18.                  <div class="float2"><input type="radio" value="cold" name="cold" id="cold" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  19.                  <div class="float1"><p>rape case investigations</p></div>
  20.                  <div class="float2"><input type="radio" value="rc" name="rc" id="rc" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  21.                  <div class="float1"><p>missing, kidnapped or exploited children</p></div>
  22.                  <div class="float2"><input type="radio" value="missing" name="missing" id="missing" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  23.                  <div class="float1"><p>tracking sex offenders</p></div>
  24.                  <div class="float2"><input type="radio" value="track" name="track" id="track" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  25.                  <div class="float1"><p>stalking and sexual obsessions</p></div>
  26.                  <div class="float2"><input type="radio" value="stalk" name="stalk" id="stalk" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  27.                  <div class="float1"><p>serial sex murders</p></div>
  28.                  <div class="float2"><input type="radio" value="serial" name="serial" id="serial" onmouseup="clearText();" onmousedown="optSelectAll();" onclick=""></div>
  29.                  <div class="float1"><p>other</p></div>
  30.                  <div class="float2"><input type="radio" value="other" name="other" id="other" onmousedown="optSelectAll();" onclick="openText();"></div>
  31.                  <div class="float1"><textarea name="specify" id="specify" value="Specify other (200 characters max)" maxlength="200"></textarea></div>
  32.               </div>
  33.         </div>
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

looking at you code it seems like your doing this to unselect the other radios and if a certain one is clicked then to show a certain textarea and if the one is not the correct radio to hide it is this about right?

so why not use the radio grouping
HTML Code: [ Select ]
<input type="radio" name="sex_crime" value="cheat" /> cheat <br />
<input type="radio" name="sex_crime" value="abuse" /> abuse <br />
<input type="radio" name="sex_crime" value="disabled" /> disabled <br />
<input type="radio" name="sex_crime" value="illegal" /> illegal <br />
<input type="radio" name="sex_crime" value="exploit" /> exploit <br />
<input type="radio" name="sex_crime" value="traffick" /> traffick <br />
<input type="radio" name="sex_crime" value="cp" /> cp <br />
<input type="radio" name="sex_crime" value="cold" /> cold <br />
<input type="radio" name="sex_crime" value="rc" /> rc <br />
<input type="radio" name="sex_crime" value="missing" /> missing <br />
<input type="radio" name="sex_crime" value="track" /> track <br />
<input type="radio" name="sex_crime" value="serial" /> serial <br />
<input type="radio" name="sex_crime" value="other" /> other <br />
<input type="radio" name="sex_crime" value="stalk" /> stalk <br />
 
  1. <input type="radio" name="sex_crime" value="cheat" /> cheat <br />
  2. <input type="radio" name="sex_crime" value="abuse" /> abuse <br />
  3. <input type="radio" name="sex_crime" value="disabled" /> disabled <br />
  4. <input type="radio" name="sex_crime" value="illegal" /> illegal <br />
  5. <input type="radio" name="sex_crime" value="exploit" /> exploit <br />
  6. <input type="radio" name="sex_crime" value="traffick" /> traffick <br />
  7. <input type="radio" name="sex_crime" value="cp" /> cp <br />
  8. <input type="radio" name="sex_crime" value="cold" /> cold <br />
  9. <input type="radio" name="sex_crime" value="rc" /> rc <br />
  10. <input type="radio" name="sex_crime" value="missing" /> missing <br />
  11. <input type="radio" name="sex_crime" value="track" /> track <br />
  12. <input type="radio" name="sex_crime" value="serial" /> serial <br />
  13. <input type="radio" name="sex_crime" value="other" /> other <br />
  14. <input type="radio" name="sex_crime" value="stalk" /> stalk <br />
  15.  


Here is a quick example i setup for the textarea http://jsfiddle.net/zS2Au/ is this the functionality your looking for?
  • Kurthead+1
  • Graduate
  • Graduate
  • Kurthead+1
  • Posts: 131

Post 3+ Months Ago

Couldn't because I need to have which ever radio is selected to load into a php string, and I didn't know how to get one of the grouped radios when all of them had the same name. So I just went with what I knew, and whenever any of them are clicked, they are all cleared onmousedown. And then in the php I can just create the string based on any of the names being set i.e. if(isset($_POST['stalk'])). It's too late in the game to change them all back to grouped if I learn the php way to get the selected one of a group, because there are about 50 ha. I was able to get everything to work like that in other servers, along with the textarea. Just not in IE8. But if I don't use a loop it also works in IE8. Thanks for the example btw, I didn't think about bringing the textarea with a case.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

Ok well i did notice something in your for loop that could be causing you some issues.

Your loop
JAVASCRIPT Code: [ Select ]
var test = new Array(1,2,3,4,5,6,7,8,9,10);
for(i=0; i<test.length; i++) {
     alert('I=' + i + ' Value = ' + test[i]);
}
 
  1. var test = new Array(1,2,3,4,5,6,7,8,9,10);
  2. for(i=0; i<test.length; i++) {
  3.      alert('I=' + i + ' Value = ' + test[i]);
  4. }
  5.  


Fixed loop
JAVASCRIPT Code: [ Select ]
var test = new Array(1,2,3,4,5,6,7,8,9,10);
for(i=0; i<test.length - 1; i++) { // Notice the -1
     alert('I=' + i + ' Value = ' + test[i]);
}
 
  1. var test = new Array(1,2,3,4,5,6,7,8,9,10);
  2. for(i=0; i<test.length - 1; i++) { // Notice the -1
  3.      alert('I=' + i + ' Value = ' + test[i]);
  4. }
  5.  

the -1 is there because length starts at 1 and arrays start at 0 if you didn't have that there var i would go up to 10 but since the array starts at zero the indexes stop at 9 giving you an undefined for the last entry

Also for future references using the radio grouping you simply use the value

Example 1 the message is the same-ish
PHP Code: [ Select ]
echo 'You marked the the crime committed against you was ' . $_POST['sex_crime'];
 
  1. echo 'You marked the the crime committed against you was ' . $_POST['sex_crime'];
  2.  


Example 2 completely different messages
PHP Code: [ Select ]
 
switch($_POST['sex_crime']) {
   
    // cheat
    case 'cheat':
        echo 'we are sorry they cheated on you';
        break;
 
    // abuse
    case 'abuse':
        echo 'you were abused? we are sending someone out to tickle them with a feather until the poop their pants.';
        break;
 
    // Default message
    default:
        echo 'You marked the the crime committed against you was ' . $_POST['sex_crime'];
        break;
 
}
 
 
  1.  
  2. switch($_POST['sex_crime']) {
  3.    
  4.     // cheat
  5.     case 'cheat':
  6.         echo 'we are sorry they cheated on you';
  7.         break;
  8.  
  9.     // abuse
  10.     case 'abuse':
  11.         echo 'you were abused? we are sending someone out to tickle them with a feather until the poop their pants.';
  12.         break;
  13.  
  14.     // Default message
  15.     default:
  16.         echo 'You marked the the crime committed against you was ' . $_POST['sex_crime'];
  17.         break;
  18.  
  19. }
  20.  
  21.  


HTML for both the examples
HTML Code: [ Select ]
<input type="radio" name="sex_crime" value="cheat" /> cheat <br />
<input type="radio" name="sex_crime" value="abuse" /> abuse <br />
<input type="radio" name="sex_crime" value="disabled" /> disabled <br />
<input type="radio" name="sex_crime" value="illegal" /> illegal <br />
<input type="radio" name="sex_crime" value="exploit" /> exploit <br />
<input type="radio" name="sex_crime" value="traffick" /> traffick <br />
<input type="radio" name="sex_crime" value="cp" /> cp <br />
<input type="radio" name="sex_crime" value="cold" /> cold <br />
<input type="radio" name="sex_crime" value="rc" /> rc <br />
<input type="radio" name="sex_crime" value="missing" /> missing <br />
<input type="radio" name="sex_crime" value="track" /> track <br />
<input type="radio" name="sex_crime" value="serial" /> serial <br />
<input type="radio" name="sex_crime" value="other" /> other <br />
<input type="radio" name="sex_crime" value="stalk" /> stalk <br />
 
  1. <input type="radio" name="sex_crime" value="cheat" /> cheat <br />
  2. <input type="radio" name="sex_crime" value="abuse" /> abuse <br />
  3. <input type="radio" name="sex_crime" value="disabled" /> disabled <br />
  4. <input type="radio" name="sex_crime" value="illegal" /> illegal <br />
  5. <input type="radio" name="sex_crime" value="exploit" /> exploit <br />
  6. <input type="radio" name="sex_crime" value="traffick" /> traffick <br />
  7. <input type="radio" name="sex_crime" value="cp" /> cp <br />
  8. <input type="radio" name="sex_crime" value="cold" /> cold <br />
  9. <input type="radio" name="sex_crime" value="rc" /> rc <br />
  10. <input type="radio" name="sex_crime" value="missing" /> missing <br />
  11. <input type="radio" name="sex_crime" value="track" /> track <br />
  12. <input type="radio" name="sex_crime" value="serial" /> serial <br />
  13. <input type="radio" name="sex_crime" value="other" /> other <br />
  14. <input type="radio" name="sex_crime" value="stalk" /> stalk <br />
  15.  



ALSO (hopefully my computer doesn't shut off again while I'm typing this)
It seem like in the code your running unchecks all radios since there is no way to determine what one you clicked on, is this the desired outcome or something over looked?
If it was over looked have you considered something like
JAVASCRIPT Code: [ Select ]
function optSelectAll(omit) {
   
    // Make an array of id's
    var ids = new Array(
               'track',
               'cheat',
               'abuse',
               'disabled',
               'other');
 
    o = document.getElementById('specify');
    for(i=0;i<=ids.length-1;i++) {
       
        // Make sure the omit doesn't match the id in the array
        if(ids[i] != omit) {
           
            // Unset the radio
            document.getElementById(ids[i]).checked = false;
 
        }
       
    }
   
    if(omit == ids[4]) {
       
        o.style.visibility="visible";
   
    } else {
       
        o.style.visibility="hidden";
       
    }
       
}
 
  1. function optSelectAll(omit) {
  2.    
  3.     // Make an array of id's
  4.     var ids = new Array(
  5.                'track',
  6.                'cheat',
  7.                'abuse',
  8.                'disabled',
  9.                'other');
  10.  
  11.     o = document.getElementById('specify');
  12.     for(i=0;i<=ids.length-1;i++) {
  13.        
  14.         // Make sure the omit doesn't match the id in the array
  15.         if(ids[i] != omit) {
  16.            
  17.             // Unset the radio
  18.             document.getElementById(ids[i]).checked = false;
  19.  
  20.         }
  21.        
  22.     }
  23.    
  24.     if(omit == ids[4]) {
  25.        
  26.         o.style.visibility="visible";
  27.    
  28.     } else {
  29.        
  30.         o.style.visibility="hidden";
  31.        
  32.     }
  33.        
  34. }
  35.  

HTML Code: [ Select ]
<input type="radio" value="track" name="track" id="track" onmousedown="optSelectAll(this.name);" onclick="" />
<input type="radio" value="cheat" name="cheat" id="cheat" onmousedown="optSelectAll(this.name);" onclick="" />
<input type="radio" value="abuse" name="abuse" id="abuse" onmousedown="optSelectAll(this.name);" onclick="" />
<input type="radio" value="disabled" name="disabled" id="disabled" onmousedown="optSelectAll(this.name);" onclick="" />
<input type="radio" value="other" name="other" id="other" onmousedown="optSelectAll(this.name);" onclick="" />
<textarea id="specify" style="visibility:hidden">specify</textarea>
 
  1. <input type="radio" value="track" name="track" id="track" onmousedown="optSelectAll(this.name);" onclick="" />
  2. <input type="radio" value="cheat" name="cheat" id="cheat" onmousedown="optSelectAll(this.name);" onclick="" />
  3. <input type="radio" value="abuse" name="abuse" id="abuse" onmousedown="optSelectAll(this.name);" onclick="" />
  4. <input type="radio" value="disabled" name="disabled" id="disabled" onmousedown="optSelectAll(this.name);" onclick="" />
  5. <input type="radio" value="other" name="other" id="other" onmousedown="optSelectAll(this.name);" onclick="" />
  6. <textarea id="specify" style="visibility:hidden">specify</textarea>
  7.  


.... I made it with out the battery dying

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 54 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.