[Javascript] Reset the value of a SET of fields
David Yee
david at amsresponse.com
Thu May 20 13:12:44 CDT 2004
Thanks for all the input! That's cool to see so many ways to do the same
thing in Javascript.
> -----Original Message-----
> From: Flavio Gomes [mailto:flavio at economisa.com.br]
> Sent: Thursday, May 20, 2004 6:43 AM
> To: [JavaScript List]
> Subject: Re: [Javascript] Reset the value of a SET of fields
>
> David,
>
> well.... there are html errors in your code:
> "type=first_name_1" is not valid. Probably you wanted to
> write something like this:
>
> <input type="text" name="first_name_1" size="10">
>
> Right? And in your function you may refer to "first_name_1"
> element this way:
>
> <script language=javascript>
> function clear_row(form_name, num)
> {
> oFirstName = document.getElementsByName('first_name_' + num);
> oLastName = document.getElementsByName('last_name_' + num);
> oEmail = document.getElementsByName('e_mail_' + num);
>
> oFirstName[0].value = ''; // [0] is used because the function
> oLastName[0].value = ''; // returns an array with all objects
> oEmail[0].value = ''; // that match the passed name.
> }
> </script>
>
>
> --
> Flavio Gomes
> flavio at economisa.com.br
>
>
>
> 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
>
More information about the Javascript
mailing list