1
I have three lines with four fields input
of the kind time
, and I want to create a button so that the two lines below can be filled equal to the first.
I’m following this reply from Soen, and adapted to take by classe
instead of id
, then I can already fill several fields from one, but I want, from a button, to provide the fill of the line below with the value of the other four of the line above (see image below).
The HTML of the lines:
<label id="Cseg2" class="hora">Linha 1:</label>
<label for="Cseg3">Entrada:</label>
<input type="time" id="Cseg3" name="Tsegs">
<label for="Cseg4">Saída:</label>
<input type="time" id="Cseg4" name="Tsegss">
<label for="Cseg5">Retorno:</label>
<input type="time" id="Cseg5" name="Tsegsss">
<label for="Cseg6">Saída:</label>
<input type="time" id="Cseg6" name="Tsegssss">
<br>
<label id="Cter2" class="hora">Linha 2:</label>
<label for="Cter3">Entrada:</label>
<input type="time" id="Cter3" name="Tter">
<label for="Cter4">Saída:</label>
<input type="time" id="Cter4" name="Tters">
<label for="Cter5">Retorno:</label>
<input type="time" id="Cter5" name="Tterss">
<label for="Cter6">Saída:</label>
<input type="time" id="Cter6" name="Ttersss">
<br>
<label id="Cqua2" class="hora">Linha 3:</label>
<label for="Cqua3">Entrada:</label>
<input type="time" id="Cqua3" name="Tqua">
<label for="Cqua4">Saída:</label>
<input type="time" id="Cqua4" name="Tquas">
<label for="Cqua5">Retorno:</label>
<input type="time" id="Cqua5" name="Tquass">
<label for="Cqua6">Saída:</label>
<input type="time" id="Cqua6" name="Tquasss">
<br>
For now I managed to get here by working on the Soen script:
var tags = [];
$(function() {
$('#tagAdd').click(function(){
//get the tag value and trim the spaces
var tVal = $('#tagEntry').val().trim();
if(tVal == '')
return;
//verify tag not already saved
for(var i=0;i<tags.length;i++)
if(tags[i] == tVal)
return;
//add the tag to the array
tags.push(tVal);
//set the tags entry box
$('.tagsEntered').val(tags.join(', '));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<strong>Enter your tag and click add</strong>
<br/>
<input type="time" id="tagEntry" />
<button id="tagAdd">Add</button>
</div>
<div>
<strong>Entered Tags</strong>
<br/>
<input type="time" class="tagsEntered"/>
</div>
<div>
<strong>Entered Tags 2</strong>
<br/>
<input type="time" class="tagsEntered"/>
</div>
<div>
<strong>Entered Tags3</strong>
<br/>
<input type="time" class="tagsEntered"/>
</div>
The result I hope is something like this:
The solution can be in simple javascript, with jQuery, or even with Bootstrap.
Lucas, the script is working fine, but in addition to correctly including the values in the other fields, it is sending my form when I click the button. How can I make it so that he does not send the form, just fill in the fields. Ah, and in phpstorm
(function(index, value)
message appearsunused parameter value
. Do I need to adapt something? I thank you already, thanks.– gustavox
Ah, I got through
onclick="addItem(); return false;"
. ^^ Source: http://stackoverflow.com/a/932657/4734177– gustavox
Nah, I thought it worked but I guess it was just the lag. :/
– gustavox
I forgot to include the JS... it’s not working yet, but I think I’m on the way here. :-)
– gustavox
LOL The answer below http://stackoverflow.com/a/10836076/4734177 simplified everything: only include in HTML
type="button"
. :-)– gustavox
That’s it. By default, the button submits. I modified the answer there
– Lucas