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

Getting the equiv 'upper bound' of a form

P: n/a
Hello all,

I'm trying to do some form validation on a form that collects its data into
a multidimensional array, and on submitting that re-writes the values as
hidden form elements (a form that keeps adding submitted values to a
multidimensional array).

However, since the hidden form fields have to be identically named to the
visible form fields, I can't make my JavaScript return an error if the field
is blank because there are already fields in the form that are filled.

Essentially, I need a way to refer to the /last/ field in my form with a
given name, instead of the /first/, to check to see if it is empty.

Thanks,
Ken
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Kenneth wrote:
Essentially, I need a way to refer to the /last/ field in my form with a
given name, instead of the /first/, to check to see if it is empty.


Untested:

function getLastFieldNamed(oForm, sName)
{
if (oForm
&& oForm.elements
&& sField
&& oForm.elements[sName])
{
var e = oForm.elements[sName];
return (e[0] ? e[e.length - 1] : e);
}

return null;
}

var fld = getLastFieldNamed(document.forms["foo"], "bar");
if (fld)
{
// ...
}
HTH

PointedEars
Jul 20 '05 #2

P: n/a
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote :
Untested:

function getLastFieldNamed(oForm, sName)
{
if (oForm
&& oForm.elements
&& sField
What is sField?
&& oForm.elements[sName])
{
var e = oForm.elements[sName];
return (e[0] ? e[e.length - 1] : e);
}

return null;
}

var fld = getLastFieldNamed(document.forms["foo"], "bar");
if (fld)
{
// ...
}
HTH

PointedEars

Jul 20 '05 #3

P: n/a
Vjekoslav Begovic wrote:
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote :
function getLastFieldNamed(oForm, sName)
{
if (oForm
&& oForm.elements
&& sField


What is sField?


s/Field/Name/g

Sorry, my bad. Changed the argument's identifier and forgot that line.
PointedEars
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.