javascript thread: Validating multiple text boxes with same name.
You just get an array of them, so loop through it and check each one.
Something like this:
function checkAreas()
{
var bAreaEntered = false;
for (var i=0; i<document.formname.area.length; i++)
{
if (document.formname.area[i].value != "")
{
bAreaEntered = true;
break;
}
}
if (bAreaEntered)
alert("at least one area entered");
else
alert("no areas entered");
}
hth
Phil
>-----------------------------------------
> Hi All
> Hope someone can help... I have a form for entry of search criteria that
a> llows the user to specify multiple geographic areas for the search.
W> hen submitted, the form data is passed to an ASP page to do the search.
> Have nearly all the validation done but can't work this one out... how
do
I> validate with javascript that at least one text box called 'area' has
b> een used???
> Am using an external script file for validating on submit and want
t> o 'return false' if none of the area boxes have been used.
> Code for the relevant part of the form is below:
> <tr bgcolor="<%=ROW_MID%>">
> <td width="20%" style="padding-left: 4px"><div
c> lass="header" align="left">Areas</div></td>
> <td width="40%" style="padding: 1px"><input type="Text"
n> ame="area" maxlength="20" size="20" class="textboxrequired"></td>
> <td width="40%" style="padding: 1px"><input type="Text"
n> ame="area" maxlength="20" size="20" class="textboxrequired"></td>
> </tr>
> <tr bgcolor="<%=ROW_MID%>">
> <td width="20%" style="padding: 1px"> </td>
> <td width="40%" style="padding: 1px"><input type="Text"
n> ame="area" maxlength="20" size="20" class="textboxrequired"></td>
> <td width="40%" style="padding: 1px"><input type="Text"
n> ame="area" maxlength="20" size="20" class="textboxrequired"></td>
> </tr>
> <tr bgcolor="<%=ROW_MID%>">
> <td width="20%" style="padding: 1px"> </td>
> <td width="40%" style="padding: 1px"><input type="Text"
n> ame="area" maxlength="20" size="20" class="textboxrequired"></td>
> <td width="40%" style="padding: 1px"><input type="Text"
n> ame="area" maxlength="20" size="20" class="textboxrequired"></td>
> </tr>
> <tr bgcolor="<%=ROW_MID%>">
> <td width="20%" style="padding: 1px"> </td>
> <td width="40%" style="padding: 1px"><input type="Text"
n> ame="area" maxlength="20" size="20" class="textboxrequired"></td>
> <td width="40%" style="padding: 1px"><input type="Text"
n> ame="area" maxlength="20" size="20" class="textboxrequired"></td>
> </tr>
> Hope someone can help.
> Many thanks
> Dominic