...

View Full Version : Radio button validation?



angst
05-26-2006, 06:20 PM
hello,
I've got 4 radio buttons on an html page.

named: account_can | options, Yes & No / 1 & 0
named: account_usa | options, Yes & No / 1 & 0

my script:

function checkcurrency(){

var strCan = document.supplier.account_can;
var strUS = document.supplier.account_usa;

if(strCan.value==1 && strUS.value==1){
alert("The supplier must be either a Canadian or US account, it can not be both.");
return false;
}
return true;
}

every time i submit the form, it goes through no matter what i've selected.

and I have added this to the form onsubmit tag. so I'm not sure why this isn't working..

any ideas?

thanks in advance for your time!
-Ken

miranda
05-26-2006, 07:19 PM
try this instead


function checkcurrency(){

var strCan = document.supplier.account_can[0];
var strUS = document.supplier.account_usa[0];

if(strCan.checked==true && strUS.checked==true){
alert("The supplier must be either a Canadian or US account, it can not be both.");
return false;
}
return true;
}

this is assuming that yes is the 1st button in each of the 2 groups. if it is the 2nd button then it becomes
var strCan = document.supplier.account_can[1];
var strUS = document.supplier.account_usa[1];

because javascript starts counting at 0

angst
05-26-2006, 09:03 PM
ah, ok i see.

thats exactly what i needed.

thanks!!
-Ken



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum