florida
06-16-2004, 04:06 PM
Please advise as I would like to make sure a textbox is populated if a Checkbox is selected.
My Checkbox has two selections with one already checked:
Account<input TYPE="Radio" name="account" value="Yes" CHECKED />Yes
<input TYPE="Radio" name="account" value="No" />No
<br>
Names<TEXTAREA COLS="12" ROWS="3" NAME="names" WRAP="soft"></TEXTAREA>
Now I need to make sure if it is checked "Yes" then a message will come up if the "Names" Box is blank.
If the checkbox is checked with a "No" and the "Names" box is populated then I need an alert message saying the "No" checkbox should not be checked if the "Names" field is populated.
My attempt:
var checked;
if(document.myformnamehere.account.checked.value == "Yes")
{
checked = true;
if(document.myformnamehere.names.value == "")
{
alert("names needs to be populated if account request is checked with yes");
return false;
}
}
else if(document.myformnamehere.account.checked.value == "No")
{
checked = true;
if(document.myformnamehere.names.value != "")
{
alert("names can not be populated if account request is checked with no");
return false;
}
}
My Checkbox has two selections with one already checked:
Account<input TYPE="Radio" name="account" value="Yes" CHECKED />Yes
<input TYPE="Radio" name="account" value="No" />No
<br>
Names<TEXTAREA COLS="12" ROWS="3" NAME="names" WRAP="soft"></TEXTAREA>
Now I need to make sure if it is checked "Yes" then a message will come up if the "Names" Box is blank.
If the checkbox is checked with a "No" and the "Names" box is populated then I need an alert message saying the "No" checkbox should not be checked if the "Names" field is populated.
My attempt:
var checked;
if(document.myformnamehere.account.checked.value == "Yes")
{
checked = true;
if(document.myformnamehere.names.value == "")
{
alert("names needs to be populated if account request is checked with yes");
return false;
}
}
else if(document.myformnamehere.account.checked.value == "No")
{
checked = true;
if(document.myformnamehere.names.value != "")
{
alert("names can not be populated if account request is checked with no");
return false;
}
}