Radio Button Value If Statment Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mokoena

    #1

    Radio Button Value If Statment Problem

    I can't seem to do an if statement check on the value returned from a
    selected radio button (isexistingleag ue[1]). The code never runs anything
    within the if statement that tests if "true" is returned, even though an
    alert shortly before the if statement shows that the value returned *is*
    true. See in-line comments for more details.

    Any ideas what the problem is?





    function submit_reg_user ()
    {
    var FailedCheck;
    var newuserleague;

    FailedCheck = false;

    if (document.Regis terUser.email.v alue == "")
    {
    FailedCheck = true;
    }

    if (document.Regis terUser.usernam e.value == "")
    {
    FailedCheck = true;
    }

    if (document.Regis terUser.newpass word1.value == "")
    {
    FailedCheck = true;
    }

    if (document.Regis terUser.newpass word2.value == "")
    {
    FailedCheck = true;
    }

    // I use this alert to display the value in the radio button
    // It displays "true" when checked, which is what i want
    alert('++++' + document.Regist erUser.isexisti ngleague[1].checked + '++++')

    //the code doesn't seem to pass this check
    if (document.Regis terUser.isexist ingleague[1].checked == "true")
    {
    // it never displays this alert, even when the above alert
    // displays "true"
    alert("Its made it here");
    if (document.Regis terUser.newleag ue.value == "")
    {
    alert("Its now made it here");
    FailedCheck = true;
    }
    }

    if (FailedCheck == true)
    {
    alert("You have not completed one of the fields correctly.");
    }

    else
    {
    alert('You cannot currently register. Please try again later.');
    //document.Regist erUser.submit() ;
    }
    }



  • Janwillem Borleffs

    #2
    Re: Radio Button Value If Statment Problem


    "Mokoena" <walalala@micro soft.com> wrote in message
    news:be1lkl$a3a 3$2@ID-83837.news.dfnc is.de...[color=blue]
    > I can't seem to do an if statement check on the value returned from a
    > selected radio button (isexistingleag ue[1]). The code never runs anything
    > within the if statement that tests if "true" is returned, even though an
    > alert shortly before the if statement shows that the value returned *is*
    > true. See in-line comments for more details.
    >
    > Any ideas what the problem is?
    >[/color]
    .....[color=blue]
    >
    > // I use this alert to display the value in the radio button
    > // It displays "true" when checked, which is what i want
    > alert('++++' + document.Regist erUser.isexisti ngleague[1].checked +[/color]
    '++++')[color=blue]
    >
    > //the code doesn't seem to pass this check
    > if (document.Regis terUser.isexist ingleague[1].checked == "true")
    > {
    >[/color]

    The evaluation returns a boolean (true) and not a string ("true"). The
    latter is only the case when you would apply the valueOf() or toString()
    method.

    You should do it like this:

    if (document.Regis terUser.isexist ingleague[1].checked == true)

    or better yet:

    if (document.Regis terUser.isexist ingleague[1].checked)


    JW



    Comment

    Working...