Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Radio button validation?

    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

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    try this instead

    Code:
    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

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ah, ok i see.

    thats exactly what i needed.

    thanks!!
    -Ken


  •  

    Posting Permissions

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