Is one (1) a 'length' for option buttons?
Hi:
I have the following need: based on an email address entered into a text box, a table is created with contact information for records that match the email address, one per row.
The last row will always have a 'Create new contact'. In the case of no matching contact records, it will be the only row. Option buttons are included with each row in order to identify the selection. Depending on the selection, different forms are opened when the form is submitted. So far, no problems with any of this.
I'm concerned that after a group of records is brought down, that the user will edit the email address. If that happens, especially if a selection is made, then the action of the submit button is ambiguous. So, I've been trying to use the onchange() event to
1) determine if a selection was made and, if so, unset it
2) hide (or eliminate) the table so it is obvious to the user what the submit button should do
This works for the most part with the following exception: when there are no matching records, the only possible selection is 'Add new contact'. If I check that, then change the email address, the table does not hide, and the option button does not reset, BUT if I click submit, it works as intended: it gets any matching contact records for the new email address rather than the predefined page.
Below are code snippets of the HTML and javascript.
Here is the only clue I have:
When contact records that match the email address are found, then the option group has a length in the javascript.
When no contact records are found and only the 'New contact record' option button displays, the length propery diplays 'undefined'.
I don't understand that. Isn't one (1) a length?
Thanks,
JK
Here is the page source when matching contacts are found:
================================================== =======
<div id=divContactSelections>
<Table Border=1 id=tblContactSelections>
<TR>
<TD class='copy'><INPUT Type=radio Name=radContactID Value=C6UJ9A003RSB onclick=setTargetPageID(40)></TD>
<TD class='copy'>Juan Rey</TD>
</TR>
<TR>
<TD class='copy'><INPUT Type=radio Name=radContactID Value=C6UJ9A002H6E onclick=setTargetPageID(40)></TD>
<TD class='copy'>John King</TD>
</TR>
<TR>
<TD class='copy'><INPUT Type=radio Name=radContactID Value=NewContact onclick=setTargetPageID(30)></TD>
<TD class='copy'>Create New Contact</TD>
</TR>
</Table>
</div>
Here is the page source when no matching contacts are found:
================================================== ==========
<div id=divContactSelections>
<Table Border=1 id=tblContactSelections>
<TR>
<TD class='copy'><INPUT Type=radio Name=radContactID Value=NewContact onclick=setTargetPageID(30)></TD>
<TD class='copy'>Create New Contact</TD>
</TR>
</Table>
</div>
Here is the javascript function I'm using for the onchange event for the text box:
================================================== ================================
function checkSelection()
{
var blnHideContactSelections = false; //initialize flag
if (document.frmCustomerEmail.radContactID != null) // determine if option buttons exist yet
// initial load of page vs subsequent load
{
var ctlGroup = document.frmCustomerEmail.radContactID; // option button name
var intNumberOfControls = ctlGroup.length; // identify how many options are available
alert(intNumberOfControls);
var element;
var controlIndex;
for (controlIndex=0; controlIndex < intNumberOfControls; controlIndex++) // loop through
{
element = ctlGroup[controlIndex];
if (element.checked == true) // if the item is checked
{
element.checked = false // uncheck it
blnHideContactSelections = true // set flag
break; // exit for
}
}
}
if (blnHideContactSelections == true)
{
document.getElementById("tblContactSelections").st yle.visibility = "hidden"; // hide the table
document.getElementById("tblContactSelections").st yle.display = "none"; // recover the canvas
}
}
|