» in my experience...

» home | about | contact | résumé
» archives | donate | rss syndication

»
»
I own this record.


Communiblog Communiblog expressed as RSS 2.0
Here at IMX
Memes R' Us
freetheaudio2.jpg
SuperNova 1987A from 1994 to 2003
GarageBand

Getting form values for validation.
[ Posted by Dan on September 04, 2003 | 1 Comments ]

Here's a quick little JavaScript that steps thru a form and reports the value of each element within that form, whatever the length of the form might be. This is a pretty easy little script to write, but I figured that since I had the need for it, someone else might too. The script looks like this...
function reportFormElements(obj)  {

for (var i = 0; i < obj.length; i++) {

	if (obj.elements[i].type == 'checkbox') {
		alert(obj.elements[i].checked);
	}
	else {
	alert(obj.elements[i].value);
	}
	
  }

}
The basic gist is, for each actual form element in the form, look at the value of the form element and alert that value. If it's a checkbox, then investigate the 'checked' attribute.

There are several ways to do this sort of thing, and one of them reports the value of each child node in the named form, including text nodes, html nodes. We don't want that, and only want to interrogate the actual form elements. A sample form is below, go ahead and try it...





checkbox

 

Hey Dan... have you ever tried QForms?
http://www.pengoworks.com/index.cfm?action=get:qforms

VERY nice little javascript API

-Posted by JC on September 4, 2003 12:39 PM




Comment posting has been turned off because I don't have enough time and will to deal with the constant comment spamming. I'm very sorry and will fix this sometime soon (soon = before 2004 ends).

MovableType AmphetaDesk
NetNewsWire BlogTree Subscribe with Bloglines RSS Feed
Copyright © 2001 - 2003 by Daniel Kapusta