ayúdenme a terminar este código del formulario que crea campos adicionales dinámicos!!!
Publicado por Eduardo (186 intervenciones) el 15/03/2020 23:32:39
Hola a todos espero me puedan ayudar..lo agradeceria mucho
tengo este código que conseguí por la web que es un formulario que crea campos adicionales con JS y así puedo introducir los datos que deseo 
me funciona todo pero no he podido dar con incluir el código para agregar los operarios adicionales en el segundo juego de operarios de los viajes...
Acá pueden verlo en funcionamiento:
http://serviaseo.net.co/reporteoficinas/formularioreportenuevo2.php
Aca pongo el código:
Acá una captura de pantalla del sistema:

mil gracias a Todos


me funciona todo pero no he podido dar con incluir el código para agregar los operarios adicionales en el segundo juego de operarios de los viajes...
Acá pueden verlo en funcionamiento:
http://serviaseo.net.co/reporteoficinas/formularioreportenuevo2.php
Aca pongo el código:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php include("scriptphpconect.php");?>
<!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=utf-8" />
<title>Formulario Detalle Conductores</title>
<script src="jquery.min.js"></script>
<!------------------------------------------------------------------------------------>
<link href="estilos.css" rel="stylesheet" type="text/css" />
<link href="estiloscampos.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="87" colspan="2" bgcolor="#FFFFFF"><img src="arriba.png" width="848" height="87" /></td>
</tr>
<tr>
<td width="735" height="15" bgcolor="#FF6600"><img src="regresar.png" width="115" height="26" /></td>
<td width="115" bgcolor="#FF6600"><img src="salirbtnn.png" width="115" height="26" /></td>
</tr>
<tr>
<td height="15" colspan="2" bgcolor="#FFFFFF" style="text-align:right" >Bienvenido <?php echo $_SESSION['nombre'] ?> - Municipio de <?php echo $_SESSION['municipio'] ?></td>
</tr>
<tr>
<td height="370" colspan="2" bgcolor="#FFA466"><table width="814" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td colspan="2">
<input name="codigo" type="hidden" id="codigo" value="<? echo $codigo ?>" />
<input name="municipio" type="hidden" id="municipio" value="<?php echo $_SESSION['municipio'] ?>" />
<input name="fecha_envio" type="hidden" id="fecha_envio" value=<? echo $fechaActual ?>" />
</td>
<td colspan="4"> </td>
</tr>
<tr>
<td width="44" height="31">Fecha:</td>
<td width="194"><input name="fecha_reporte" type="date" required id="fecha_reporte" class="campos2"/></td>
<td width="77">Conductor: </td>
<td width="212"><select name="conductor" required class="campos" id="conductor">
<option value="">Seleccione:</option>
<?php
$query = $mysqli -> query ("SELECT * FROM conductores_nom WHERE estado_conductor='activo' ORDER BY nombre_conductor ASC" );
while ($valores = mysqli_fetch_array($query)) {
echo '<option value="'.$valores[nombre_conductor].'">'.$valores[nombre_conductor].'</option>';
}
?>
</select></td>
<td width="57">Placa:</td>
<td width="199"><select name="placa" required class="campos" id="placa">
<option value="">Seleccione:</option>
<?php
$query = $mysqli -> query ("SELECT * FROM placas WHERE estado='activo' ORDER BY placa ASC");
while ($valores = mysqli_fetch_array($query)) {
echo '<option value="'.$valores[placa].'">'.$valores[placa].'</option>';
}
?>
</select></td>
</tr>
<tr>
<td height="19"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="15" colspan="6"><hr /></td>
</tr>
<tr>
<td colspan="6"><table width="805" border="0" cellpadding="1" cellspacing="1">
<tr>
<script type="text/javascript">
$(document).ready(function(){
var maxField1 = 10; //Input fields increment limitation
var addButton1 = $('.add_button1'); //Add button selector
var wrapper1 = $('.field_wrapper1'); //Input field wrapper
var fieldHTML1 = '<div><hr><label>Hora Inicio: </label><input name="hora1[]" type="text" class="hora1" autocomplete="off" id="hora1" size="5" required/><label> Hora Final: </label><input name="hora2[]" type="text" class="hora2" autocomplete="off" id="hora2" size="5" required/><label> Novedad: </label><input name="novedad[]" type="text" class="campos2" id="novedad" value="" size="20"/><br></div><div class="field_wrapper2"><div><label>Operario: </label><input name="operario[]" type="text" class="campos2" id="operario" value="" size="15"/></label><a href="javascript:void(0);" class="add_button1" title="Agregar Operario"><img src="add-icon.png" width="21" height="21" /></a></div><br>';
var x1 = 1; //Initial field counter is 1
$(addButton1).click(function(){ //Once add button is clicked
if(x1 < maxField1){ //Check maximum number of input fields
x1++; //Increment field counter
$(wrapper1).append(fieldHTML1); // Add field html
}
});
$(wrapper1).on('click', '.remove_button1', function(e){ //Once remove button is clicked
e.preventDefault();
$(this).parent('div').remove(); //Remove field html
x1--; //Decrement field counter
});
});
</script>
<td width="54" height="24">Viajes:</td>
<td width="714"><div class="field_wrapper1">
<div>
<label>Hora Inicio: </label>
<input name="hora1[]" type="text" class="hora1" autocomplete="off" id="hora1" size="5" required/>
<label>Hora Final:
<input name="hora2[]" type="text" class="hora2" autocomplete="off" id="hora2" size="5" required/>
</label>
Novedad:
<input name="novedad[]" type="text" class="campos2" id="novedad" value="" size="20"/>
<br>
</div>
<script type="text/javascript">
$(document).ready(function(){
var maxField2 = 10; //Input fields increment limitation
var addButton2 = $('.add_button2'); //Add button selector
var wrapper2 = $('.field_wrapper2'); //Input field wrapper
var fieldHTML2 = '<div id="destino2"><label>Operario: </label><input name="operario[]" type="text" class="campos2" id="operario" value="" size="15" <label> <a href="javascript:void(0);" class="remove_button2" title="Borrar Operario"><img src="remove-icon.png" width="20" height="20"/></a></div>';
var x2 = 1; //Initial field counter is 1
$(addButton2).click(function(){ //Once add button is clicked
if(x2 < maxField2){ //Check maximum number of input fields
x2++; //Increment field counter
$(wrapper2).append(fieldHTML2); // Add field html
}
});
$(wrapper2).on('click', '.remove_button2', function(e){ //Once remove button is clicked
e.preventDefault();
$(this).parent('div').remove(); //Remove field html
x2--; //Decrement field counter
});
});
</script>
<div class="field_wrapper2">
<div>
<label>Operario: </label><input name="operario[]" type="text" class="campos2" id="operario" value="" size="15" />
<label>
<a href="javascript:void(0);" class="add_button2" title="Agregar Viaje" ><img src="add-icon.png" width="20" height="20"/></a>
<tr>
<td height="24" colspan="2"><div><a href="javascript:void(0);" class="add_button2" title="Agregar Viaje" ></a></div>
</div><div></div>
</td><td width="35"><p></td>
</tr>
<tr>
<td height="24" colspan="2"><hr /></td>
<td><div><a href="javascript:void(0);" class="add_button1" title="Agregar Viaje" ><img src="add-icon.png" width="30" height="30"/></a></div></td>
</tr>
<tr>
<td height="114" colspan="3"><table width="809" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="73" height="57">Novedades Operarios:</td>
<td colspan="2"><script type="text/javascript">
$(document).ready(function(){
var maxField3 = 10; //Input fields increment limitation
var addButton3 = $('.add_button3'); //Add button selector
var wrapper3 = $('.field_wrapper3'); //Input field wrapper
var fieldHTML3 = '<div><label>Operario: </label> <input name="operarionovedades[]" type="text" class="campos2" id="operarionovedades" value="" size="15"/><label> Hora Inicio: </label> <input name="hora3[]" type="text" class="hora3" id="hora3" size="2" autocomplete="off" required/> <label> Hora Final: </label> <input name="hora4[]" type="text" class="hora4" id="hora4" autocomplete="off" size="2" required/><label> Novedad: </label> <input name="novedadoper[]" type="text" class="campos2" id="novedadoper" value="" size="15"/><a href="javascript:void(0);" class="remove_button3" title="Remove field"> <img src="remove-icon.png" width="20" height="20"/></a></div>';
var x3 = 1; //Initial field counter is 1
$(addButton3).click(function(){ //Once add button is clicked
if(x3 < maxField3){ //Check maximum number of input fields
x3++; //Increment field counter
$(wrapper3).append(fieldHTML3); // Add field html
}
});
$(wrapper3).on('click', '.remove_button3', function(e){ //Once remove button is clicked
e.preventDefault();
$(this).parent('div').remove(); //Remove field html
x3--; //Decrement field counter
});
});
</script>
<div class="field_wrapper3">
<div>
<label>Operario: </label>
<input name="operarionovedades[]" type="text" class="campos2" id="operarionovedades" value="" size="15"/>
<label>Hora Inicio: </label>
<input name="hora3[]" type="text" class="hora3" id="hora3" size="2" autocomplete="off" required/>
<label>Hora Final: </label>
<input name="hora4[]" type="text" class="hora4" id="hora4" autocomplete="off" size="2" required/>
<label>Novedad: </label>
<input name="novedadoper[]" type="text" class="campos2" id="novedadoper" value="" size="15"/>
<a href="javascript:void(0);" class="remove_button3" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>
</div>
</td>
</tr>
<tr>
<td height="26"> </td>
<td width="695"> </td>
<td width="31"><a href="javascript:void(0);" class="add_button3" title="Agregar Novedades"> <a href="javascript:void(0);" class="add_button3" title="Add field"><img src="add-icon.png" width="30" height="30"/></a></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="6"><div id="content2" style="display: none;">
</div></td>
</tr>
<tr>
<td colspan="6"></td>
</tr>
<tr>
<td colspan="6"><hr /></td>
</tr>
<tr>
<td colspan="6"> </td>
</tr>
<tr>
<td colspan="6"></td>
</tr>
<tr>
<td colspan="6"><input name="botons" type="submit" class="boton" id="button" value="Enviar" /></td>
</tr>
<tr>
<td colspan="6"> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="26" colspan="2" bgcolor="#FFFFFF"><img src="abajo.png" width="848" height="31" /></td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>
Acá una captura de pantalla del sistema:

mil gracias a Todos

Valora esta pregunta


-1