get combo field values before saving

Asked

Viewed 48 times

0

I have an html table with N values and would like to get the values of the fields (combo), property name='caption[]' before saving, just to display to the user the fields he filled in .

inserir a descrição da imagem aqui

  • Use document.getElementsByName("nameOfHTMLElement");.

  • didn’t work !

  • Can you explain better how you want to record, or what you mean by "record"? So I can also give you an answer that will help you with whatever you need.

2 answers

1

When you press the button to display the choices you will have to scroll through the elements to see what the value (choice) is in each one:

$('#check').on('click', function() {
  var escolhas = '<b>As suas escolhas são:</b><br>';
  $('select').each(function() {
     escolhas += $(this).prop('id')+ ': ' +$(this).val()+ '<br>';
  });
  $('#present').html(escolhas);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="select1">
  <option></option>
  <option value="Maria">Maria</option>
  <option value="Miguel">Miguel</option>
  <option value="Sara">Sara</option>
  <option value="Claudia">Claudia</option>
</select>
<select id="select2">
  <option></option>
  <option value="Maria">Maria</option>
  <option value="Miguel">Miguel</option>
  <option value="Sara">Sara</option>
  <option value="Claudia">Claudia</option>
</select>
<select id="select3">
  <option></option>
  <option value="Maria">Maria</option>
  <option value="Miguel">Miguel</option>
  <option value="Sara">Sara</option>
  <option value="Claudia">Claudia</option>
</select>
<br>
<button id="check">
Verificar Escolhas
</button>
<div id="present">
 
</div>

Example HERE

0

try using the following code

  var valores = $('select[name^=legenda]').map(function(idx, elem) {
    return $(elem).val();
  }).get();

it will return an Array with all values of all fields within the variable values

  • thanks Raphael, more as I use this code above ? I have created a calling function and nothing, I tried Alert and nothing ... thank you

  • if you can provide the part of your javascript code you need to use this I can give you an example of better use...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.