www.webdeveloper.com
Results 1 to 5 of 5

Thread: Javascript not working in Firefox, Chrome

  1. #1
    Join Date
    Jul 2013
    Posts
    2

    Javascript not working in Firefox, Chrome

    I have a JavaScript which works fine in IE , but does not work in Firefox or Chrome. I have pasted the code below.

    I am trying to disable everything on a form expect 4 buttons ( 2 main & 2 fa). When I try this code in Firefox, everything including the button is disabled. Please help!!

    var XYZAppCheck = document.getElementById('XYZAppCheck');
    var main_save_continue = document.getElementById("main_save_continue&q uot;
    var main_save_logout = document.getElementById("main_save_logout&quo t;
    var fa_save_continue = document.getElementById("fa_save_continue&quo t;
    var fa_save_logout = document.getElementById("fa_save_logout" );

    if (XYZAppCheck.value > 0) {

    var vform;

    var vform = document.getElementById('mainform');

    var faform;

    var faform = document.getElementById('faform');

    for (var i = 0; i < vform.length; i++) {

    vform.elements.disabled = true;

    };

    for (var i = 0; i < faform.length; i++) {

    faform.elements.disabled = true;

    };

    main_save_continue.disabled = false;
    main_save_logout.disabled = false;
    fa_save_continue.disabled = false;
    fa_save_logout.disabled = false;

    };

    };

  2. #2
    Join Date
    Nov 2010
    Posts
    1,031
    Code:
    for (var i = 0; i < vform.length; i++) {
    vform.elements.disabled = true;
    };
    does this really work in IE? what a whacky browser...

  3. #3
    Join Date
    Mar 2009
    Posts
    464
    I too am rather surprised that this code works in IE.

    Try something like...

    Code:
    for (var i = 0; i < vform.elements.length; i++) {
    
    vform.elements[i].disabled = true;
    
    };
    ..instead.

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    The action of your for loops is incorrect. An easy way is uniquely to identify the excluded elements by giving them a class like 'noDisable', then:

    Code:
    for ( var i = 0, elem; ( elem = vform.elements[ i ] ); i++ ) 
    {   
       if( !/\bnoDisable\b/i.test( elem.className ) )
         elem.disabled = true;
    };
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  5. #5
    Join Date
    Jul 2013
    Posts
    2
    Quote Originally Posted by Logic Ali View Post
    The action of your for loops is incorrect. An easy way is uniquely to identify the excluded elements by giving them a class like 'noDisable'
    can you please tell me how to give a class 'noDisable'? Sorry for my naive question, I am new to JavaScript

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles