
Originariamente inviata da
vic53
scusa lavori solo javascript? oppure asp...e javascript
ti posto due file che ho scritto al volo per farti vedere come fare (una soluzione come ce ne possono essere tante...)
il primo file l'ho chiamato TestCampi.asp ma anche se è ASP le routines sono in javascript per farti capire l'utilizzo di una forma semplice di controlli...
l'altro file che ho chiamato Risultato.asp è il file che viene attivato alla fine dei controlli dopo che hai verificato che i campi non siano spazi vuoti... naturalmente i controlli per un form di lavoro sono più complessi per questo serve come esempio
ti posto il primo file
codice:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>demo test campi</title>
<script type="text/javascript" language="javascript">
var numrows=5;
function ControllaCampi() {
var fld1;
for (var i=1; i < (numrows + 1) ; i++)
// verifica i campi inseriti
{
fld1 = "firstname" + i ;
txObj = document.getElementById(fld1);
if (txObj.value=="")
{
alert(fld1 + " non è inserito...");
txObj.focus();
return false;
}
fld1 = "lastname" + i ;
txObj = document.getElementById(fld1);
if (txObj.value=="")
{
alert(fld1 + " non è inserito...");
txObj.focus();
return false;
}
}
// se arriva qui vuol dire che i campi sono tutti diversi da spaces
document.TestCampi.action="Risultato.asp";
document.TestCampi.submit();
return true;
}
</script>
</head>
<body>
<form action="" method="POST" name="TestCampi" id="TestCampi" >
<table width="59%" border="1" cellspacing="2" cellpadding="3">
<tr bgcolor="#999999">
<th width="3%"></th>
<th width="44%">nome</th>
<th width="53%">cognome</th>
</tr>
<script language="javascript">
var numrows=5;
for (var i=1; i < (numrows + 1) ; i++)
{
document.write("<tr bgcolor='#FFFFFF'>");
document.write("<td>"+ i + "</td>");
document.write("<td><input type='text' name='firstname"+i +"' id='firstname"+ i + "' ></td>");
document.write("<td><input type='text' name='lastname"+i +"' id='lastname"+ i + "' ></td>");
document.write("</tr>");
}
</script>
</table>
<br>
<input type="button" name="btn1" value="Invia" onClick="ControllaCampi()">
</p>
</form>
</body>
</html>
ora ti posto il secondo file dove vengono visualizzati i campi....
codice:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento senza titolo</title>
</head>
<body>CAMPI INSERITI NEL FORM
<br />
<%
for i=1 to 5
response.write("firstname"&i&" = " & request.Form("firstname"&i))
response.write(" lastname"&i&" = " & request.Form("lastname"&i))
response.write("<BR>")
next
%>
</body>
</html>
spero di averti aiutato.... studiaci su
ciao