Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Disabling checkboxes with JS in Firefox
Old 12-08-2006, 07:08 PM Disabling checkboxes with JS in Firefox
Junior Talker

Posts: 4
Trades: 0
Hey, I hope someone out there can help with this! This is the first time Firefox has given me trouble where IE hasnt, unless of course Im the problem!

Basically, I have a number of checkboxes all with the name "availshifts", with various values. I have an array called "clashingShiftIDs". When a user clicks a checkbox, I need JavaScript to cycle through all of the checkboxes in "availshifts", and if any of them have a value which is present in the array, disable them. The following code sits in a function called by onClick...

if (checkbox.checked == true) {
numCheckboxes = document.bookin.availshifts.length

for ( var i=0; i< numCheckboxes; i++ ) {

if ( document.bookin.availshifts[i].disabled == false && document.bookin.availshifts[i].value != checkbox.value ) {
// alert ( "Here I am!" )
if ( isInArray(document.bookin.availshifts[i].value, clashingShiftIDs) ) {
document.bookin.availshifts[i].disabled = true;
}
}

}
}

So, this code works perfectly in IE6, but it does not work in Firefox 2. In Firefox, nothing seems to happen at all when a checkbox is ticked (besides for a tick appearing in that box). And the error console does not come up with any errors!

What makes it even more frustrating, is if I uncomment the alert in the code above, the alerts appear as it cycles through the other enabled checkboxes, and the necessary checkboxes are disabled one by one, just like they should be!

Very confused! Ive always found though that the most frustrating errors turn out to be my own fault, but I cant figure this one out!

Please help, and thanks so much for your time!

Keith
gregson09 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-09-2006, 10:24 PM Re: Disabling checkboxes with JS in Firefox
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Need to see more code. Could you post either a URL or a minimal, complete test case that illustrates the problem
logic ali is offline
Reply With Quote
View Public Profile
 
Old 12-10-2006, 09:19 AM Re: Disabling checkboxes with JS in Firefox
Junior Talker

Posts: 4
Trades: 0
Quote:
Originally Posted by logic ali View Post
Need to see more code. Could you post either a URL or a minimal, complete test case that illustrates the problem
Hello again, Ive copied in all of the relevant code below. As it is below, it does the job in both Internet Explorer and Firefox - but comes up with the annoying alert box on each iteration of the loop. If I remove the alert, it still works fine in IE, but no longer works in Firefox. Its by the far the most irritating problem Ive ever had %(

Code:
    function isInArray(elem,arr) {
    /* Returns true if elem is present in the given array, arr */
      var arrLength = arr.length;
      for ( var i=0; i<arrLength; i++ ) {
        if ( arr[i] == elem ) { return true; }
      }
      return false;
    }
    
    function handleClashes(inputCheckbox) {
      /* Returns a (possible empty) array of all the shifts which clash with the given shift */
      var xho=GetXmlHttpObject();
      if (!xho) {
        alert ("This browser does not support the technology required to use this website.");
        return false;
      }
      url = "clashes.php?function=array&selectedID=" + inputCheckbox.value;
      var clashingShiftIDs = new Array();     
      xho.onreadystatechange = function() {
        if ( xho.readyState==4) {
          clashingShiftIDs = eval("(" + xho.responseText + ")");
        } 
      }
      xho.open("GET",url,true);
      xho.send(null);       
      
      numCheckboxes = document.bookin.availshifts.length;
      if (inputCheckbox.checked == true) {
      /* Cycle through all enabled checkboxes, disable those with a value which appears in clashingShiftIDs */        
        for ( var i=0; i<numCheckboxes; i++ ) {
          iCheckbox = document.bookin.availshifts[i];
          if ( iCheckbox.disabled == false && iCheckbox.value != inputCheckbox.value ) {
            alert ( "Firefox needs this!");
            if ( isInArray(iCheckbox.value, clashingShiftIDs) ) {
              iCheckbox.disabled = true;
            }
          }
        }
I hope thats enough - thanks so much for your help!
gregson09 is offline
Reply With Quote
View Public Profile
 
Old 12-10-2006, 02:43 PM Re: Disabling checkboxes with JS in Firefox
Junior Talker

Posts: 4
Trades: 0
I found the problem! Its got nothing to do with the JavaScript, but with browser caching. If I turn caching OFF in Internet Explorer (ie. set it to check for new versions of a page at every visit to that page), then it exhibits the same behaviour as described above for Firefox. With any of the remaining 3 cache settings for Internet Explorer selected, the disabling of checkboxes using the code above works instantaneously, as checkboxes are selected.

I dont know where to start looking for a solution to this problem! Any suggestions?

Thanks very much for your help!

Keith
gregson09 is offline
Reply With Quote
View Public Profile
 
Old 12-10-2006, 06:11 PM Re: Disabling checkboxes with JS in Firefox
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by gregson09 View Post
I found the problem! Its got nothing to do with the JavaScript, but with browser caching. If I turn caching OFF in Internet Explorer (ie. set it to check for new versions of a page at every visit to that page), then it exhibits the same behaviour as described above for Firefox. With any of the remaining 3 cache settings for Internet Explorer selected, the disabling of checkboxes using the code above works instantaneously, as checkboxes are selected.

I dont know where to start looking for a solution to this problem! Any suggestions?

Thanks very much for your help!

Keith
Before anything else, I suggest that you change to using the onchange event in the checkboxes, onclick can have problems of this type.
Also you haven't shown an example of how you're calling handleClashes().
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Disabling checkboxes with JS in Firefox
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15710 seconds with 12 queries