Radio Button Value If Statment Problem

M

Mokoena

I can't seem to do an if statement check on the value returned from a
selected radio button (isexistingleague[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.RegisterUser.email.value == "")
{
FailedCheck = true;
}

if (document.RegisterUser.username.value == "")
{
FailedCheck = true;
}

if (document.RegisterUser.newpassword1.value == "")
{
FailedCheck = true;
}

if (document.RegisterUser.newpassword2.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.RegisterUser.isexistingleague[1].checked + '++++')

//the code doesn't seem to pass this check
if (document.RegisterUser.isexistingleague[1].checked == "true")
{
// it never displays this alert, even when the above alert
// displays "true"
alert("Its made it here");
if (document.RegisterUser.newleague.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.RegisterUser.submit();
}
}
 
J

Janwillem Borleffs

Mokoena said:
I can't seem to do an if statement check on the value returned from a
selected radio button (isexistingleague[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?
.....

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

//the code doesn't seem to pass this check
if (document.RegisterUser.isexistingleague[1].checked == "true")
{

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.RegisterUser.isexistingleague[1].checked == true)

or better yet:

if (document.RegisterUser.isexistingleague[1].checked)


JW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top