471,073 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

Dinamically call form fields

<script>
var arrcampi = new Array("nome", "cognome", "email", "telefono", "via",
"localita", "cap", "cosa", "dove", "stelle", "prezzomassimo",
"nrsingole", "nrdoppie", "nrtriple", "dalgiorno", "dalmese", "dalanno",
"algiorno", "almese", "alanno");

for (i=0;i<=(arrcampi.length-1);i++){
document.mh./*here*/arrcampi[i].value = "";
}
</script>

I would like to pass form fields name from an array and "reset them all".

It doesn't work.

Which is the prob?

Any help much appreciated.

Best regards.

--
Fabri
(Incredibile come si tenda a credere di piu` a Rossi. (cit.))
Jul 23 '05 #1
2 927
Fabri wrote:
<script>
var arrcampi = new Array("nome", "cognome", "email", "telefono", "via",
"localita", "cap", "cosa", "dove", "stelle", "prezzomassimo",
"nrsingole", "nrdoppie", "nrtriple", "dalgiorno", "dalmese", "dalanno",
"algiorno", "almese", "alanno");

for (i=0;i<=(arrcampi.length-1);i++){
document.mh./*here*/arrcampi[i].value = "";
}
</script>

I would like to pass form fields name from an array and "reset them all".

It doesn't work.

Which is the prob?


The problem is that you didn't read the group FAQ.

http://jibbering.com/faq/#FAQ4_39
document.forms['mh'].elements[arrcampi[i]].value = '';

but if you want to reset the entire form, why not just
document.forms['mh'].reset() ?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #2
Randy Webb wrote:
The problem is that you didn't read the group FAQ.

http://jibbering.com/faq/#FAQ4_39
document.forms['mh'].elements[arrcampi[i]].value = '';
Yes, I'm very sorry. Thank you very much :-(
but if you want to reset the entire form, why not just
document.forms['mh'].reset() ?


I have another question about it:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script>
function f(){

document.A.nome.value = "Fabri";
alert(document.A.nome.value);
document.A.reset();
alert(document.A.nome.value);
}
</script>

</head>
<body>
<form name="B">
<input type="text" name="nome" value="">
<input type="reset" value="Cancella">
</form>

<form name="A">
<input type="hidden" name="nome" value="">
</form>

<a href="#" onClick="f();">Go!</a>
</body>
</html>

This page doesn't work if the input is of type hidden.

Switching form name from A to B it works.

Why?

Regards.

--
Fabri
(Incredibile come si tenda a credere di piu` a Rossi. (cit.))
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Development | last post: by
3 posts views Thread by josepm | last post: by
2 posts views Thread by Fabio Cavassini | last post: by
32 posts views Thread by Mateo | last post: by
reply views Thread by Chepre | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.