By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,025 Members | 2,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,025 IT Pros & Developers. It's quick & easy.

Radio Button Value If Statment Problem

P: n/a
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();
}
}

Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Mokoena" <wa******@microsoft.com> wrote in message
news:be***********@ID-83837.news.dfncis.de...
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

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.