jQuery serializeArray() funktioniert nicht
    
ebody
    
    
      
    
  - jquery
 nicht angemeldet
 nicht angemeldetHallo,
ich möchte die Werte aus den Formular Textfeldern auslesen und versuche das mit serializeArray().
Wenn ich das Array ausgebe ist es immer leer. Hat jemand ein Idee warum?
$( document ).ready(function() {
  
  function getValues(){
    
    // let fields = $(':input').serializeArray(); 
    let fields = $('form > input:text').serializeArray(); 
    console.log('fields', fields); // gibt leeres Array aus
    jQuery.each(fields, function( i, field ) {
      $( "#results" ).append( field.value + " " );
    });
    
  }
  
  $('button').click(getValues);
  
});
<form id="form_data">
  <input type="text" id="ch1" value="">
  <label for="ch1">check1</label>
  <input type="text" id="ch2">
  <label for="ch2">check2</label>   
  <input type="text" id="ch3">
  <label for="ch3">check3</label>  
  <button type="button">Run</button>
</form>  
<p id="results"></p>
Gruß ebody
Hallo,
let fields = $('form > input:text').serializeArray();
warum willst du die Liste der Inputs serialisieren? Lass das .serializeArray() mal weg.
Gruß
Jürgen
Man muss den <input> Feldern das Attribut Name hinzufügen. Jetzt funktioniert es.
<form id="form_data">
  <input type="text" id="ch1" value="" name="ch1">
  <label for="ch1">check1</label>
  <input type="text" id="ch2" name="ch2">
  <label for="ch2">check2</label>   
  <input type="text" id="ch3" name="ch3">
  <label for="ch3">check3</label>  
  <button type="button">Run</button>
</form>  
<p id="results"></p>
Gruß ebody
Man muss den <input> Feldern das Attribut Name hinzufügen.
Ja. Muss man grundsätzlich wenn man die Daten haben will. Hat also nichts mit jquery zu tun.