[Javascript] Reset the value of a SET of fields
Flavio Gomes
flavio at economisa.com.br
Thu May 20 08:42:37 CDT 2004
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
>
>
More information about the Javascript
mailing list