[Project_owners] Using XPath to validate fields

David Murray lid2000 at tpg.com.au
Wed Mar 30 23:10:06 EST 2005


In case anyone needs some shoddily written code for future reference, 
here you go:

function ValidateFields(page) {
	var pagenum = page.pageStep - 1;
	if (pagenum < 0) {
		pagenum = 0;
	}
	var textboxes = 
page.getElementsByTagName("wizardpage")[pagenum].getElementsByTagName("textbox"); 

	for (z = 0; z < textboxes.length; z++) {
		if (textboxes[z].getAttribute("type") != "password") {
			if (textboxes[z].value.trim().length < 1) {
				alert("Please ensure you have filled in all the required fields 
before continuing.");
				textboxes[z].focus();
				return false;
			}
		}
	}
	return true;
}

Thanks a heap Neil. I have been bashing my head against the wall for 5 
hours trying to figure this out.

David.


David Murray wrote:

> Wow. Clearly I am an idiot. Thanks!
> 
> David Murray wrote:
> 
>> I thought that didn't go beyond one level...? *checks*
>>
>> Neil wrote:
>>
>>> David Murray wrote:
>>>
>>>>    var xp = "//wizard/wizardpage[" + pagenum + "]//textbox";
>>>>    var textboxes = evaluateXPath(page, xp);
>>>
>>>
>>>
>>>
>>> Why not just use var textboxes = 
>>> document.documentElement.currentPage.getElementsByTagName("textbox");
>>> _______________________________________________
>>> Project_owners mailing list
>>> Project_owners at mozdev.org
>>> http://mozdev.org/mailman/listinfo/project_owners
>>>
>>>
>>>
>>>
>>
>> _______________________________________________
>> Project_owners mailing list
>> Project_owners at mozdev.org
>> http://mozdev.org/mailman/listinfo/project_owners
>>
>>
>>
>>
> 
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
> 
> 
> 
> 



More information about the Project_owners mailing list