|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Dec 2003
Messaggi: 1759
|
[JSP] ottenere name e value da un tag <input>
Ho una form creata dinamicamente in una jsp a seguito di una query sul DB.
Le righe sono il contenuto del result set ottenuto e rappresentano un elenco di ingredienti. Alla fine di ogni riga c'è un campo di testo nel quale inserire la quantità che si vuole acquistare di quell'ingrediente. <input type="text" id="ingrediente<%= i %>" name="<%= rs.getString("nome") %>" value="0" /> l'attributo name contiene il nome dell'ingrediente, value la quantità che se ne vuole acquistare. Ho aggiunto l'attributo id in modo che ogni input si chiami in modo facilmente rintracciabile nella servlet visto che altrimenti non saprei come fare prendendo l'attributo name che varia a seconda della query. Il mio problema è questo: nella servlet mi serve sapere sia l'attributo name che value per ogni campo che presenti un valore > 0, ma non so come fare, riesco a prendere value, ma non name. Come posso fare? questa e la form: Codice HTML:
<form name="rimanenze" action="VerificaRimanenze" method="post"> <table width="650" border="0" cellpadding="6"> <tr> <td width="25%"><strong>Ingrediente</strong></td> <td width="25%"><p align="center"><strong>Unità di misura</strong></p></td> <td width="20%"><p align="center"><strong>Disponibilità</strong></p></td> <td width="20%"><p align="center"><strong>Soglia</strong></p></td> <td width="10%"><p align="center"><strong>Acquista</strong></p></td> </tr> <% rs = IngrController.getInEsaurimento(); while(rs.next()) { %> <tr> <td><%= rs.getString("nome") %> </td> <td><%= rs.getString("unitaDiMisura") %></td> <td><%= rs.getString("disponibilita") %></td> <td><div align="center"><%= rs.getString("soglia") %></div></td> <td><div align="center"><input type="text" id="ingrediente<%= i %>" name="<%= rs.getString("nome") %>" value="0" onChange="selezionato(this)" /></div></td> </tr> <%i++; } %> <tr> <td> </td> <td> </td> <td> </td> <td><input type="hidden" name="totale_selezionati" value="0"/> </td> <td><input type="submit" name="acquista" value="Acquista" /></td> </tr> </table> Questo è il metodo doPost della servlet Codice PHP:
|
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Dec 2003
Messaggi: 1759
|
Ho risolto aggiungendo un altro campo nascosto.
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 19:08.