Hi there,
I do server-side programming using JSP's (Java Server Pages). The HTML and javascript code is created dynamically. The page will contain a form. However, the contents of the form may vary with numerous textfields. So, the number of fields in the form will vary as will their values. When I create a page and it loads in the clients browser, I need some javascript code that will determine what fields are present in the form, their names and values. I need to do something like this:
Is this possible to do in javascript? Is there a way to determine what elements are in a form, like getting an enumeration of the objects therein?
Alan
I do server-side programming using JSP's (Java Server Pages). The HTML and javascript code is created dynamically. The page will contain a form. However, the contents of the form may vary with numerous textfields. So, the number of fields in the form will vary as will their values. When I create a page and it loads in the clients browser, I need some javascript code that will determine what fields are present in the form, their names and values. I need to do something like this:
Code:
function getElements(form)
{
var elements = new Array();
elements = form.getElements(); //of course, there's no such function!
var names = new Array();
var values = new Array();
for(i = 0; i < elements.length; i++)
{
names[i] = elements[i].name;
values[i] = elements[i].value;
}
...
... do something with the names and value arrays...
}
Alan