JavaScript - quien me ayuda con esto por favor...

 
Vista:
Imágen de perfil de Eduardo
Val: 159
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

quien me ayuda con esto por favor...

Publicado por Eduardo (176 intervenciones) el 30/01/2020 18:21:19
Tengo el siguiente problema

tengo el siguiente codigo que me hace que el campo hora salga a medida que escribo en el salga ne el formato 00:00

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
<div class="field_wrapper">
                <div>
                  <label>Hora Inicio: </label>
                  <input name="hora1" type="text" class="hora1" id="hora1" size="5" />
<label>Hora Final:
  <input name="hora2" type="text" class="hora2" id="hora2" size="5" />
</label>
<script>
	document.querySelector('.hora1').addEventListener('keypress',validateHour);
	document.querySelector('.hora1').addEventListener('blur',formatHour);
		document.querySelector('.hora2').addEventListener('keypress',validateHour);
	document.querySelector('.hora2').addEventListener('blur',formatHour);
 
	function validateHour(e){
		e.preventDefault();
		if ( !isNaN(e.key) || e.key==':' ) {
			var position = this.selectionStart;
			var text = this.value;
			var textStart = text.substr(0,position);
			var textEnd   = text.substr(this.selectionEnd);
 
			if ( (textStart+textEnd).search(':')!=-1 && e.key==':' ) return;
			var textNew = textStart + e.key + textEnd;
			textNew = textNew.replace(':','');
			if ( textNew.length>2 ){
				textStart = textNew.substr(0,textNew.length-2);
				textEnd   = textNew.substr(-2);
				textNew = textStart + ':' + textEnd;
				position++;
			} else if ( textNew>59 ) {
				textStart = textNew.substr(0,1);
				textEnd   = textNew.substr(1);
				textNew = textStart + ':' + textEnd;
				position++;
			}
 
			var textPart=textNew.split(':');
 
			if ( textPart.length == 2 && textPart[0]>23 || textPart[1]>59 ) return;
 
			this.value = textNew;
 
			this.selectionStart = position+1;
			this.selectionEnd = position+1;
		}
	}
 
	function formatHour(){
		var text = this.value;
		if ( text!="" ) {
			textPart = text.split(':');
 
			if ( textPart.length == 2 ) {
				textPart[0]=textPart[0].padStart(2,'0');
				textPart[1]=textPart[1].padStart(2,'0');
			} else {
				textPart.push(textPart[0].padStart(2,'0'));
				textPart[0]='00';
			}
			this.value=textPart.join(':');
		}
	}
</script>
 
                  Novedad:
                  <input name="novedad[]" type="text" class="campos2" id="novedad[]" value="" size="30"/>
                </div>
              </div>


Pero mas adelante a ese escript se le da la opcion de agregar dinamicamente campos adicionales para agregar y agregar mas datos correspondientes

en esta parte del codigo hace eso posible:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<script src="jquery.min.js"></script>
<!--------------SCRIPT PARA PRIMER JUEGO DE FORMULARIOS VIAJES--------------------->
<script type="text/javascript">
$(document).ready(function(){
    var maxField = 10; //Input fields increment limitation
    var addButton = $('.add_button'); //Add button selector
    var wrapper = $('.field_wrapper'); //Input field wrapper
	//name="hora1" type="text" autofocus="autofocus" class="hora1" id="hora1" size="5"
    var fieldHTML = '<div><label>Hora Inicio: </label><input type="text" name="hora1[]" value="" required class="hora1" id="hora1" size="5"/> <label>Hora Final: </label><input type="text" name="hora2[]" value="" required class="hora2" id="hora1" size="5"/> <label>Novedad: </label><input type="text" name="field_name_novedad[]" value="" size="30" class="campos2"/> <a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>'; //New input field html
    var x = 1; //Initial field counter is 1
    $(addButton).click(function(){ //Once add button is clicked
        if(x < maxField){ //Check maximum number of input fields
            x++; //Increment field counter
            $(wrapper).append(fieldHTML); // Add field html
        }
    });
    $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
        e.preventDefault();
        $(this).parent('div').remove(); //Remove field html
        x--; //Decrement field counter
    });
});
</script>

todo funciona bien solo que en esa parte no se como insertar que se llame a la función js que da a los nuevos campos que aparecen dinamicamente (hora) la misma posibilidad de agregar hora en este formato 00:00 ya que estos campos nuevos que salen se comportan como simples campos tipo Text.

acá pongo el código completo:


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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<!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>
<?php
  $mysqli = new mysqli('localhost', 'usuario', 'contrasena', 'Basededatos');
  ?>
<script src="jquery.min.js"></script>
<!--------------SCRIPT PARA PRIMER JUEGO DE FORMULARIOS VIAJES--------------------->
<script type="text/javascript">
$(document).ready(function(){
    var maxField = 10; //Input fields increment limitation
    var addButton = $('.add_button'); //Add button selector
    var wrapper = $('.field_wrapper'); //Input field wrapper
	//name="hora1" type="text" autofocus="autofocus" class="hora1" id="hora1" size="5"
    var fieldHTML = '<div><label>Hora Inicio: </label><input type="text" name="hora1[]" value="" required class="hora1" id="hora1" size="5"/> <label>Hora Final: </label><input type="text" name="hora2[]" value="" required class="hora2" id="hora1" size="5"/> <label>Novedad: </label><input type="text" name="field_name_novedad[]" value="" size="30" class="campos2"/> <a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>'; //New input field html
    var x = 1; //Initial field counter is 1
    $(addButton).click(function(){ //Once add button is clicked
        if(x < maxField){ //Check maximum number of input fields
            x++; //Increment field counter
            $(wrapper).append(fieldHTML); // Add field html
        }
    });
    $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
        e.preventDefault();
        $(this).parent('div').remove(); //Remove field html
        x--; //Decrement field counter
    });
});
</script>
<!--------------SCRIPT PARA SEGUNDO JUEGO DE FORMULARIOS HORAS EXTRAS--------------------->
<script type="text/javascript">
$(document).ready(function(){
    var maxField = 10; //Input fields increment limitation
    var addButton = $('.add_button2'); //Add button selector
    var wrapper = $('.field_wrapper2'); //Input field wrapper
<!----------name="field_name[]"------------------>
    var fieldHTML = '<div><label>Operario: </label><input name="operario" type="text" style="text-transform:uppercase;" class="campos2" onkeyup="javascript:this.value=this.value.toUpperCase();"/> <label>Hora Inicio: </label><input type="text" name="hora3[]" value="" required class="hora1" id="hora1" size="5"/><label> Hora Final: </label><input type="text" name="hora4[]" value="" required class="hora4" id="hora1" size="5"/> <a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>'; //New input field html
    var x = 1; //Initial field counter is 1
    $(addButton).click(function(){ //Once add button is clicked
        if(x < maxField){ //Check maximum number of input fields
            x++; //Increment field counter
            $(wrapper).append(fieldHTML); // Add field html
        }
    });
    $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
        e.preventDefault();
        $(this).parent('div').remove(); //Remove field html
        x--; //Decrement field counter
    });
});
</script>
<!---------------------------SCRIPT PARA MOSTRAR DIVS---------------------------------------->
<script type="text/javascript">
    function showContent() {
        element = document.getElementById("content");
        check = document.getElementById("check");
        if (check.checked) {
            element.style.display='block';
        }
        else {
            element.style.display='none';
        }
    }
</script>
<script type="text/javascript">
    function showContent2() {
        element2 = document.getElementById("content2");
        check2 = document.getElementById("check2");
        if (check2.checked) {
            element2.style.display='block';
        }
        else {
            element2.style.display='none';
        }
    }
</script>
<!------------------------------------------------------------------------------------->
<script language="JavaScript">
function confirmar_envio(){
if (confirm('¿Seguro de enviar los datos?, ¿Revise si existen Horas Extras?'))
{
        document.form1.submit()
     }
}
</script>
<!------------------------------------------------------------------------------>
<!------------------------------------------------------------------------------>
<style type="text/css">
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
}
<!---------------------------------------
</style>
<link href="estilos.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#apDiv1 {
	position: absolute;
	left: 134px;
	top: 9px;
	width: 848px;
	height: 87px;
	z-index: 1;
}
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="procesa.php">
  <table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td height="87" bgcolor="#FFFFFF"><a href="salir.php"><img src="arriba.png" width="848" height="87" /></a></td>
    </tr>
    <tr>
      <td height="370" bgcolor="#FFA466"><table width="814" border="0" align="center" cellpadding="2" cellspacing="2">
        <tr>
          <td width="45">&nbsp;</td>
          <td width="192"><input name="municipio" type="hidden" id="municipio" value="<? echo $_SESSION['s_usuario'];  ?>" /></td>
          <td colspan="4">&nbsp;</td>
        </tr>
        <tr>
          <td height="31">Fecha:</td>
          <td><input name="fecha_reporte" type="date" required id="fecha_reporte" class="campos2"/></td>
          <td width="71">Conductor: </td>
          <td width="231"><select name="conductor" class="campos" id="conductor">
            <option value="0">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="41">Placa:</td>
          <td width="199"><select name="placa" class="campos" id="placa">
            <option value="0">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">&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td height="15" colspan="6"><hr /></td>
        </tr>
        <tr>
          <td colspan="6"><table width="805" border="0" cellpadding="2" cellspacing="2">
            <tr>
              <td width="63" height="24">Viajes:</td>
              <td colspan="4"><div class="field_wrapper">
                <div>
                  <label>Hora Inicio: </label>
                  <input name="hora1" type="text" class="hora1" id="hora1" size="5" />
<label>Hora Final:
  <input name="hora2" type="text" class="hora2" id="hora2" size="5" />
</label>
<script>
	document.querySelector('.hora1').addEventListener('keypress',validateHour);
	document.querySelector('.hora1').addEventListener('blur',formatHour);
		document.querySelector('.hora2').addEventListener('keypress',validateHour);
	document.querySelector('.hora2').addEventListener('blur',formatHour);
	function validateHour(e){
		e.preventDefault();
		if ( !isNaN(e.key) || e.key==':' ) {
			var position = this.selectionStart;
			var text = this.value;
			var textStart = text.substr(0,position);
			var textEnd   = text.substr(this.selectionEnd);
			if ( (textStart+textEnd).search(':')!=-1 && e.key==':' ) return;
			var textNew = textStart + e.key + textEnd;
			textNew = textNew.replace(':','');
			if ( textNew.length>2 ){
				textStart = textNew.substr(0,textNew.length-2);
				textEnd   = textNew.substr(-2);
				textNew = textStart + ':' + textEnd;
				position++;
			} else if ( textNew>59 ) {
				textStart = textNew.substr(0,1);
				textEnd   = textNew.substr(1);
				textNew = textStart + ':' + textEnd;
				position++;
			}
			var textPart=textNew.split(':');
			if ( textPart.length == 2 && textPart[0]>23 || textPart[1]>59 ) return;
			this.value = textNew;
			this.selectionStart = position+1;
			this.selectionEnd = position+1;
		}
	}
	function formatHour(){
		var text = this.value;
		if ( text!="" ) {
			textPart = text.split(':');
			if ( textPart.length == 2 ) {
				textPart[0]=textPart[0].padStart(2,'0');
				textPart[1]=textPart[1].padStart(2,'0');
			} else {
				textPart.push(textPart[0].padStart(2,'0'));
				textPart[0]='00';
			}
			this.value=textPart.join(':');
		}
	}
</script>
                  Novedad:
                  <input name="novedad[]" type="text" class="campos2" id="novedad[]" value="" size="30"/>
                </div>
              </div></td>
            </tr>
            <tr>
              <td height="28">&nbsp;</td>
              <td width="196">&nbsp;</td>
              <td width="167">&nbsp;</td>
              <td width="283">&nbsp;</td>
              <td width="64"><a href="javascript:void(0);" class="add_button" title="Add field"><img src="add-icon.png" width="24" height="24"/></a></td>
            </tr>
          </table></td>
          </tr>
        <tr>
          <td colspan="6"><div id="content2" style="display: none;">
            <textarea name="novedad" id="novedad" cols="100" rows="4"></textarea>
            </div></td>
        </tr>
        <tr>
          <td colspan="6"></td>
          </tr>
        <tr>
          <td colspan="6"><hr /></td>
        </tr>
        <tr>
          <td colspan="6"><table width="809" border="0" cellpadding="2" cellspacing="2">
            <tr>
              <td width="107" height="57">Horas Extras:</td>
              <td colspan="2"><div class="field_wrapper2">
                <div>
                  <label>Operario: </label>
                  <input name="operario[]" type="text" style="text-transform:uppercase;" required="required" class="campos2" value="" id="operario[]" onkeyup="javascript:this.value=this.value.toUpperCase();"/>
                  <label>Hora Inicio: </label>
                  <input name="hora3" type="text" class="hora3" id="hora3" size="5" />
<label>Hora Final: </label>
<input name="hora4" type="text" class="hora4" id="hora4" size="5" />
<script>
	document.querySelector('.hora3').addEventListener('keypress',validateHour);
	document.querySelector('.hora3').addEventListener('blur',formatHour);
		document.querySelector('.hora4').addEventListener('keypress',validateHour);
	document.querySelector('.hora4').addEventListener('blur',formatHour);
	function validateHour(e){
		e.preventDefault();
		if ( !isNaN(e.key) || e.key==':' ) {
			var position = this.selectionStart;
			var text = this.value;
			var textStart = text.substr(0,position);
			var textEnd   = text.substr(this.selectionEnd);
			if ( (textStart+textEnd).search(':')!=-1 && e.key==':' ) return;
			var textNew = textStart + e.key + textEnd;
			textNew = textNew.replace(':','');
			if ( textNew.length>2 ){
				textStart = textNew.substr(0,textNew.length-2);
				textEnd   = textNew.substr(-2);
				textNew = textStart + ':' + textEnd;
				position++;
			} else if ( textNew>59 ) {
				textStart = textNew.substr(0,1);
				textEnd   = textNew.substr(1);
				textNew = textStart + ':' + textEnd;
				position++;
			}
			var textPart=textNew.split(':');
			if ( textPart.length == 2 && textPart[0]>23 || textPart[1]>59 ) return;
			this.value = textNew;
			this.selectionStart = position+1;
			this.selectionEnd = position+1;
		}
	}
	function formatHour(){
		var text = this.value;
		if ( text!="" ) {
			textPart = text.split(':');
			if ( textPart.length == 2 ) {
				textPart[0]=textPart[0].padStart(2,'0');
				textPart[1]=textPart[1].padStart(2,'0');
			} else {
				textPart.push(textPart[0].padStart(2,'0'));
				textPart[0]='00';
			}
			this.value=textPart.join(':');
		}
	}
</script>
<a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></div>
                </div><div></div>                <a href="javascript:void(0);" class="add_button2" title="Add field"></a></td>
              </tr>
            <tr>
              <td height="28">&nbsp;</td>
              <td width="613">&nbsp;</td>
              <td width="69"><a href="javascript:void(0);" class="add_button2" title="Add field"><img src="add-icon.png" width="24" height="24"/></a></td>
            </tr>
            </table></td>
        </tr>
        <tr>
          <td colspan="6"></td>
          <!-------<input type="submit" name="button" id="button" onclick="confirmar_envio()" value="Enviar" />-------------->
        </tr>
        <tr>
          <td colspan="6"><input name="button" type="submit" class="boton" id="button" value="Enviar" /></td>
        </tr>
        <tr>
          <td colspan="6">&nbsp;</td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td height="26" bgcolor="#FFFFFF"><img src="abajo.png" width="848" height="31" /></td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro
Val: 1.448
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

quien me ayuda con esto por favor...

Publicado por Alejandro (532 intervenciones) el 30/01/2020 19:12:23
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
La función para la hora debes corregirla.

Solo tienes que agregar el listener a los nuevos elementos.

1
2
3
4
5
6
7
8
<div id="destino"></dv>
<script>
   $('#destino').on('keypress','.hora',validateHour);
   $('#destino').on('blur','.hora',formatHour);
   for(i=0; i<5; i++){
      $('#destino').append(<input type="text" class="hora" />)
   }
</script>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de EDUARDO
Val: 159
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

quien me ayuda con esto por favor...

Publicado por EDUARDO (176 intervenciones) el 30/01/2020 20:15:59
Hola muchas gracias por responder en que parte pongo el Script que me enviaste.. ;)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Alejandro
Val: 1.448
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

quien me ayuda con esto por favor...

Publicado por Alejandro (532 intervenciones) el 30/01/2020 20:35:38
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
No es para que lo pongas, es un ejemplo para que tu lo adaptes.

1
2
3
4
5
<div id="destino"></dv> //es donde se estarán agregando los nuevos elementos.
 
$('#destino').on('keypress','.hora',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
 
$('#destino').append('<input type="text" class="hora" />') //Agrega inputs al elemento "destino".
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Eduardo
Val: 159
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

quien me ayuda con esto por favor...

Publicado por Eduardo (176 intervenciones) el 30/01/2020 21:33:29
Hola Alejandro, yo sigo sin entender.. no soy muy experto en le tema, aca pongo el script que hace que se adicionen al formulario los campos dinamicos pero no se en que parte poner lo que me dices que haga.. me echarias una mano.. por fa..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<script type="text/javascript">
$(document).ready(function(){
    var maxField = 10; //Input fields increment limitation
    var addButton = $('.add_button'); //Add button selector
    var wrapper = $('.field_wrapper'); //Input field wrapper
	//name="hora1" type="text" autofocus="autofocus" class="hora1" id="hora1" size="5"
    var fieldHTML = '<div><label>Hora Inicio: </label><input type="text" name="hora1[]" value="" required class="hora1" id="hora1" size="5"/> <label>Hora Final: </label><input type="text" name="hora2[]" value="" required class="hora2" id="hora1" size="5"/> <label>Novedad: </label><input type="text" name="field_name_novedad[]" value="" size="30" class="campos2"/> <a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>';
	//New input field html
    var x = 1; //Initial field counter is 1
    $(addButton).click(function(){ //Once add button is clicked
        if(x < maxField){ //Check maximum number of input fields
            x++; //Increment field counter
            $(wrapper).append(fieldHTML); // Add field html
        }
    });
    $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
        e.preventDefault();
        $(this).parent('div').remove(); //Remove field html
        x--; //Decrement field counter
    });
});
</script>


Captura
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Alejandro
Val: 1.448
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

quien me ayuda con esto por favor...

Publicado por Alejandro (532 intervenciones) el 30/01/2020 22:19:19
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
Trata de entenderlo, es sencillo si lo intentas, prácticamente es lo mismo que haces con el botón de remover.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Eduardo
Val: 159
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

quien me ayuda con esto por favor...

Publicado por Eduardo (176 intervenciones) el 31/01/2020 14:27:11
Hola Alejandro un saludo desde Colombia.. te cuento que aun no me resulta he puesto el codigo por todas partes y aun nada.. Help me please!!

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
<!--------------SCRIPT PARA PRIMER JUEGO DE FORMULARIOS VIAJES--------------------->
<script type="text/javascript">
$(document).ready(function(){
    var maxField = 10; //Input fields increment limitation
    var addButton = $('.add_button'); //Add button selector
    var wrapper = $('.field_wrapper'); //Input field wrapper
	//name="hora1" type="text" autofocus="autofocus" class="hora1" id="hora1" size="5"
    var fieldHTML = '<div id="destino"><label>Hora Inicio: </label><input type="text" name="hora1[]" value="" required class="hora1" id="hora1" size="5"/> <label>Hora Final: </label><input type="text" name="hora2[]" value="" required class="hora2" id="hora1" size="5"/> <label>Novedad: </label><input type="text" name="field_name_novedad[]" value="" size="30" class="campos2"/> <a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>';
	//New input field html
    var x = 1; //Initial field counter is 1
    $(addButton).click(function(){ //Once add button is clicked
        if(x < maxField){ //Check maximum number of input fields
            x++; //Increment field counter
            $(wrapper).append(fieldHTML); // Add field html
        }
    });
    $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
        e.preventDefault();
        $(this).parent('div').remove(); //Remove field html
        x--; //Decrement field counter
    });
});
$('#destino').on('keypress','.hora1',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
$('#destino').append('<input type="text" class="hora1" />') //Agrega inputs al elemento "destino".
</script>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Alejandro
Val: 1.448
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

quien me ayuda con esto por favor...

Publicado por Alejandro (532 intervenciones) el 31/01/2020 15:43:06
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
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
<!--------------SCRIPT PARA PRIMER JUEGO DE FORMULARIOS VIAJES--------------------->
<script type="text/javascript">
	$(document).ready(function(){
		var maxField = 10; //Input fields increment limitation
		var addButton = $('.add_button'); //Add button selector
		var wrapper = $('.field_wrapper'); //Input field wrapper
		//name="hora1" type="text" autofocus="autofocus" class="hora1" id="hora1" size="5"
		var fieldHTML = '<div id="destino"><label>Hora Inicio: </label><input type="text" name="hora1[]" value="" required class="hora1" id="hora1" size="5"/> <label>Hora Final: </label><input type="text" name="hora2[]" value="" required class="hora2" id="hora1" size="5"/> <label>Novedad: </label><input type="text" name="field_name_novedad[]" value="" size="30" class="campos2"/> <a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>';
		//New input field html
		var x = 1; //Initial field counter is 1
		$(addButton).click(function(){ //Once add button is clicked
			if(x < maxField){ //Check maximum number of input fields
				x++; //Increment field counter
				$(wrapper).append(fieldHTML); // Add field html
			}
		});
		$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
			e.preventDefault();
			$(this).parent('div').remove(); //Remove field html
			x--; //Decrement field counter
		});
		$(wrapper).on('keypress','.hora1',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
		$(wrapper).on('blur','.hora1',formatHour);
	});
</script>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Eduardo
Val: 159
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

quien me ayuda con esto por favor...

Publicado por Eduardo (176 intervenciones) el 31/01/2020 16:10:09
FUNCIONAAAAAAA!!! mil graciasssss

pero tengo un problema en el segundo juego de campos no funciona y les agregue las lineas

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
<!--------------SCRIPT PARA PRIMER JUEGO DE FORMULARIOS ESTE ESTA LISTO--------------------->
<script type="text/javascript">
	$(document).ready(function(){
		var maxField = 10; //Input fields increment limitation
		var addButton = $('.add_button'); //Add button selector
		var wrapper = $('.field_wrapper'); //Input field wrapper
		//name="hora1" type="text" autofocus="autofocus" class="hora1" id="hora1" size="5"
		var fieldHTML = '<div id="destino"><label>Hora Inicio: </label><input type="text" name="hora1[]" value="" required class="hora1" id="hora1" size="5"/> <label>Hora Final: </label><input type="text" name="hora2[]" value="" required class="hora2" id="hora1" size="5"/> <label>Novedad: </label><input type="text" name="field_name_novedad[]" value="" size="30" class="campos2"/> <a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>';
		//New input field html
		var x = 1; //Initial field counter is 1
		$(addButton).click(function(){ //Once add button is clicked
			if(x < maxField){ //Check maximum number of input fields
				x++; //Increment field counter
				$(wrapper).append(fieldHTML); // Add field html
			}
		});
		$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
			e.preventDefault();
			$(this).parent('div').remove(); //Remove field html
			x--; //Decrement field counter
		});
			//LINEAS QUE ENVIO MI GRAN AMIGO ALEJANDRO PRIMER JUEGO DE CAMPOS-------------------------------------------------
		$(wrapper).on('keypress','.hora1',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
		$(wrapper).on('blur','.hora1',formatHour);
		$(wrapper).on('keypress','.hora2',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
		$(wrapper).on('blur','.hora2',formatHour);
	});
</script>
<!--------------SCRIPT PARA SEGUNDO JUEGO DE FORMULARIOS HORAS EXTRAS ESTYE AUN NO --------------------->
<script type="text/javascript">
$(document).ready(function(){
    var maxField = 10; //
    var addButton = $('.add_button2'); //agrega
    var wrapper = $('.field_wrapper2'); //wrapper
<!----------name="field_name[]"------------------>
    var fieldHTML = '<div id="destino2"><label>Operario: </label><input name="operario" type="text" style="text-transform:uppercase;" class="campos2" onkeyup="javascript:this.value=this.value.toUpperCase();"/> <label>Hora Inicio: </label><input type="text" name="hora3[]" value="" required class="hora1" id="hora1" size="5"/><label> Hora Final: </label><input type="text" name="hora4[]" value="" required class="hora4" id="hora1" size="5"/> <a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>'; //New input field html
    var x = 1; //Initial field counter is 1
    $(addButton).click(function(){ //Once add button is clicked
        if(x < maxField){ //Check maximum number of input fields
            x++; //Increment field counter
            $(wrapper).append(fieldHTML); // Add field html
        }
    });
    $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
        e.preventDefault();
        $(this).parent('div').remove(); //Remove field html
        x--; //Decrement field counter
    });
	//LINEAS QUE ENVIO MI GRAN AMIGO ALEJANDRO SEGUNDO JUEGO DE CAMPOS-------------------------------------------------
		$(wrapper2).on('keypress','.hora3',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
		$(wrapper2).on('blur','.hora3',formatHour);
		$(wrapper2).on('keypress','.hora4',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
		$(wrapper2).on('blur','.hora4',formatHour);
 
});
 
</script>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Eduardo
Val: 159
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

quien me ayuda con esto por favor...

Publicado por Eduardo (176 intervenciones) el 31/01/2020 16:23:15
Funciona Perfecto esa parte.. mil gracias,, pero tengo un problema en el segundo juego de campos le agregue la lineas y en ese no me funciona por que?

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
<script src="jquery.min.js"></script>
<!--------------SCRIPT PARA PRIMER JUEGO DE FORMULARIOS ESTE ESTA LISTO--------------------->
<script type="text/javascript">
	$(document).ready(function(){
		var maxField = 10; //Input fields increment limitation
		var addButton = $('.add_button'); //Add button selector
		var wrapper = $('.field_wrapper'); //Input field wrapper
		//name="hora1" type="text" autofocus="autofocus" class="hora1" id="hora1" size="5"
		var fieldHTML = '<div id="destino"><label>Hora Inicio: </label><input type="text" name="hora1[]" value="" required class="hora1" id="hora1" size="5"/> <label>Hora Final: </label><input type="text" name="hora2[]" value="" required class="hora2" id="hora1" size="5"/> <label>Novedad: </label><input type="text" name="field_name_novedad[]" value="" size="30" class="campos2"/> <a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>';
		//New input field html
		var x = 1; //Initial field counter is 1
		$(addButton).click(function(){ //Once add button is clicked
			if(x < maxField){ //Check maximum number of input fields
				x++; //Increment field counter
				$(wrapper).append(fieldHTML); // Add field html
			}
		});
		$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
			e.preventDefault();
			$(this).parent('div').remove(); //Remove field html
			x--; //Decrement field counter
		});
			//LINEAS QUE ENVIO MI GRAN AMIGO ALEJANDRO PRIMER JUEGO DE CAMPOS-------------------------------------------------
		$(wrapper).on('keypress','.hora1',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
		$(wrapper).on('blur','.hora1',formatHour);
		$(wrapper).on('keypress','.hora2',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
		$(wrapper).on('blur','.hora2',formatHour);
	});
</script>
<!--------------SCRIPT PARA SEGUNDO JUEGO DE FORMULARIOS HORAS EXTRAS ESTYE AUN NO --------------------->
<script type="text/javascript">
$(document).ready(function(){
    var maxField2 = 10; //
    var addButton2 = $('.add_button2'); //agrega
    var wrapper2 = $('.field_wrapper2'); //wrapper
<!----------name="field_name[]"------------------>
    var fieldHTML2 = '<div id="destino2"><label>Operario: </label><input name="operario" type="text" style="text-transform:uppercase;" class="campos2" onkeyup="javascript:this.value=this.value.toUpperCase();"/> <label>Hora Inicio: </label><input type="text" name="hora3[]" value="" required class="hora1" id="hora1" size="5"/><label> Hora Final: </label><input type="text" name="hora4[]" value="" required class="hora4" id="hora1" size="5"/> <a href="javascript:void(0);" class="remove_button" title="Remove field"><img src="remove-icon.png" width="20" height="20"/></a></div>'; //New input field html
    var x = 1; //Initial field counter is 1
    $(addButton2).click(function(){ //Once add button is clicked
        if(x < maxField2){ //Check maximum number of input fields
            x++; //Increment field counter
            $(wrapper2).append(fieldHTML2); // Add field html
        }
    });
    $(wrapper2).on('click', '.remove_button', function(e){ //Once remove button is clicked
        e.preventDefault();
        $(this).parent('div').remove(); //Remove field html
        x--; //Decrement field counter
    });
	//LINEAS QUE ENVIO MI GRAN AMIGO ALEJANDRO SEGUNDO JUEGO DE CAMPOS-------------------------------------------------
		$(wrapper2).on('keypress','.hora3',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
		$(wrapper2).on('blur','.hora3',formatHour);
		$(wrapper2).on('keypress','.hora4',validateHour); //para el elemento dentro de destino que tenga la clase "hora", cuando se presione la tecla ejecuta la función validateHour
		$(wrapper2).on('blur','.hora4',formatHour);
 
});
 
</script>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar