0
I am trying to make a small form based on HTML, CSS and simple Javascript (without Jquery).
In one of the parts of this form, I would like any option
selected from a select
appear in the textarea
separated by commas or lines. In addition, the sum of the values of the selected products must appear in the value field.
Until then, I was able to make the values appear, however, I cannot make everything that is clicked in the text area appear. Here’s what I’ve done so far:
function M() {
document.getElementById("produtos").value = document.getElementById("LstMesas").value;
}
function C() {
document.getElementById("produtos").value = document.getElementById("LstCadeiras").value;
}
function calculaValor(formT) {
var custo1 = document.getElementById("LstCadeiras");
var cadeira = custo1.options[custo1.selectedIndex].value;
var custo2 = document.getElementById("LstMesas");
var mesa = custo2.options[custo2.selectedIndex].value;
cadeira = parseFloat(cadeira);
mesa = parseFloat(mesa);
var total = cadeira + mesa;
document.getElementById("valor").value = total;
}
</fieldset>
<fieldset class="fsResEsq">
<legend> Produtos</legend> <br/> Mesas:
<select size="1" id="LstMesas" name="LstMesas" class="entDir" onchange="calculaValor()" , "M()">
<option value="0" selected></option>
<optgroup label="Diretor">
<option value="500.00">Alfamob Sigma - R$500,00</option>
<option value="360.00">Alfa Painel S40M136 - R$360,00</option>
</optgroup>
<optgroup label="Reunião">
<option value="370.00">Alfamob Corp. semi-oval - R$370,00</option>
</optgroup>
</select><br/>
<br/>Cadeiras:
<select size="1" id="LstCadeiras" name="LstCadeiras" class="entDir" onchange="calculaValor()" , "C()">
<option value="0" selected></option>
<optgroup label="Secretária">
<option value="190.00">Veneza 658 Fixa Couro - R$190,00</option>
<option value="300.00">Turim Gir. Couro - R$300,00</option>
<option value="200.00">Matriz Exp. Gir. Tecido - R$200,00</option>
</optgroup>
<optgroup label="Presidente">
<option value="620.00">Firenze 560 Couro - R$620,00</option>
<option value="800.00">Ipanema Prime Couro - R$800,00</option>
</optgroup>
</select><br/>
<textarea readonly type="text" class="lstSel" id="produtos"></textarea><br/>
<br/>Valor total: <input readonly type="text" name="TxtValor" class="shwValor" id="valor" />
<br/><br/>
</fieldset>
Thanks for the help. In fact, I would like the text area to show any <option> I select from my <select>, and not their values. I don’t know if I made myself clear...
– Wellington Pimentel
what do you say is an option? An option has a value and text
– user76097
I only meant that, in the text area, I would like the name of the option to appear (Ex: when clicking on Alfamob(...), the same would be for the text area). Already the value should go to the Input Value. In this way you described me, what goes to the text area is the value of the products. Forgive me if I lacked clarity. The answer below illustrates what I tried to say.
– Wellington Pimentel
briefly, what you want is the option text in the textarea.
– user76097
Exactly! The text of the option when clicking on it. Again, forgive me if I lacked clarity in the explanation.
– Wellington Pimentel
quiet, we are here to learn and to doubt.
– user76097