Ich habe ein modales Popup mit einem Formular, und ich versuche, die Werte zu erhalten, um eine UL-Liste auf der Seite anzufügen.Anhängen von Formularvariablen an das übergeordnete Element aus dem modalen Popup funktioniert nicht
Dies ist der HTML:
<div id="breakfast">
<p>BREAKFAST</p>
<p>
<ul class="breakfastlist">
</ul></p>
<p align="center"><a href="#breakfastPop" rel="modal:open">ADD FOOD</a></p>
</div>
<div id="breakfastPop" class="modal" style="max-width: 680px;">
<div id="custom" style="background-color: fff; border: 0;">
<p>Select your food for BREAKFAST</p><br>
<div>FOOD/PREPARATION/PORTION<br>
<form class="breakfastform">
<?php
include('includes/mealpicker.php');
?></div>
<div style="text-align: center;"># PROTEINS<br>
<input type="text" name="num_protein" style="width: 45px;"></div>
<div style="text-align: center;"># CARBS<br>
<input type="text" name="num_carbs" style="width: 45px;"></div>
</div>
<p align="center"><input type='submit' value="ADD FOOD" /></p>
</form>
</div>
Dies ist die JS:
<script type="text/javascript">
$('#breakfastPop form').on('submit', function(){
var to_append = $('select') +' - '+ $('input[name=num_protein]') +' - '+ $('input[name=num_carbs]');
$('.breakfastlist').append('<li>'+ to_append + '</li>');
$(this).parent().hide();
return false;
});
</script>
Jede Hilfe sehr geschätzt wird.
Danke
So jetzt, Sie Anfügen tatsächlich die gesamte ausgewählte Elemente selbst, anstatt jeden Textwert. Verwenden Sie zum Beispiel '$ ('input [name = num_protein]'). val()' stattdessen. – Snowmonkey