Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count number of radios maybe disable submit

Status
Not open for further replies.

jamert

Programmer
Dec 9, 2007
80
CA
Hi i'm trying to count the number of radio groups on a page and if less than 80% do not have a selection then disable the submit button, other wise enable it. I'm putting an onclick on each radio to call the function, plus a window.lonad event to call the same function. This is the function i have wich seems ill, any thoughts?
Code:
function countRadio(){
  var allR = document.getElementsByTagName('input');
  int a=1;
    for(var i=0;i<allR.length;i++){ 
        if(allR[i].type=='radio'){ 
        a++;
        }
    }
    int Rcount = allR.length;
    Rcount = Rcount%80;
    if (Rcount < a)
    {
    document.forms[0].elements['Button1'].disabled = true;
    document.forms[0].elements['Button2'].disabled = true;
    }
}

Thanks
 
got it figured, hope it helps someone:

Code:
countRadio();

function countRadio(){
  var allR = document.getElementsByTagName('input');
  var a=0;
  var b=0;
    for(var i=0; i<allR.length; i++){ 
        if(allR[i].type=='radio') { b++; }      
        if(allR[i].type=='radio' && allR[i].checked) { a++; } 
    }
    
    var rdoPercent = Math.round(b*0.8);
    if (a < rdoPercent)
    {
    document.forms[0].elements['Button1'].disabled = true; document.forms[0].elements['Button2'].disabled = true;
    }
    else
    {
    document.forms[0].elements['Button1'].disabled = false; document.forms[0].elements['Button2'].disabled = false;
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top