[Javascript] Reset the value of a SET of fields
David Yee
david at amsresponse.com
Wed May 19 20:37:26 CDT 2004
Hey thanks for the help guys- these are a great help. I'll have to remember
to close the input tags.
> -----Original Message-----
> From: Paul Novitski [mailto:paul at novitskisoftware.com]
> Sent: Wednesday, May 19, 2004 6:10 PM
> To: [JavaScript List]
> Subject: Re: [Javascript] Reset the value of a SET of fields
>
> David,
>
> Your HTML:
>
> ><input type=first_name_1 size=10>
>
> mis-uses the type attribute. It would more properly be:
>
> <input type="text" name="first_name_1" size="10" />
>
> (I suggest further that future-looking markup puts all
> attributes in quotes and terminates uncloseable tags with />
> a la XHTML.)
>
> Next, if this were my page I would make the task of referring
> to each group of fields easier by containing each group, like:
>
> <div id="group1">
> <input type="text" name="first_name_1" size="10" />
> <input type="text" name="last_name_1" size="10" />
> <input type="text" name="email_1" size="10" />
> </div>
>
> That allows your clear function to work like this:
>
> function clear_row(num)
> {
> // point to the group container
> var oGroup = document.getElementById("group" + num)
>
> // get an array of all its children
> var aFields = oGroup.getElementByTagName("INPUT")
> // or:
> var aFields = oGroup.childNodes
>
> // clear each one
> for (var iField=0; iField < aFields.length; iField++)
> {
> aFields[iField].value = ""
> }
> }
>
> Cheers,
> Paul
>
>
> At 05:00 PM 5/19/2004, David Yee wrote:
> >Hi all. How can I write a function that will reset the
> value of a SET
> >of fields (in this case, first_name_2, last_name_2, and
> email_2 would
> >constitute one set) to blank? Basically this function will
> linked by a
> >button next to each set of fields.
> >
> ><form name=my_form method=POST>
> ><input type=first_name_1 size=10>
> ><input type=last_name_1 size=20>
> ><input type=email_1 size=30>
> >
> ><input type=first_name_2 size=10>
> ><input type=last_name_2 size=20>
> ><input type=email_2 size=30>
> >
> ><input type=first_name_2 size=10>
> ><input type=last_name_2 size=20>
> ><input type=email_2 size=30>
> ></form>
> >
> >
> >I tried something like:
> >
> ><script language=javascript>
> >function clear_row(form_name, num)
> >{
> > document.form_name.first_name + num = '';
> > document.form_name.last_name + num = '';
> > document.form_name.email + num = ''; } </script>
> >
> >
> >One button would be like:
> >
> ><input type=button onclick="clear_row(myform, 2)">
> >
> >But obviously the syntax is wrong in the function. Thanks
> for any help.
> >
> >David
> >_______________________________________________
> >Javascript mailing list
> >Javascript at LaTech.edu
> >https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
More information about the Javascript
mailing list