javascript - Handling unknown number of form values -
i have form which, besides other properties, has link, open modal window enter additional information. additional information unknown when form generated, need generate these items once have been created. thinking might append <form>
, wrap <div>
every pair of data entered in <div>
, , calculate how data entered.
my form looks
my question is: how handle scenario? please ask if left unclear.
the question seemed js specific , have not added of asp mvc stuff in snippet , worked around functionality of adding shoes. have take account list needs posted server save changes. think outside scope of question
$(function (){ // shoe add $('#savevalue').click(function(){ // shoe name var shoename = $('.modal-body input:first').val(); // shoe number var shoenum = $('.modal-body input:last').val(); // create structure add list $('#addedvalues ul').append("<li> shoe name: <strong>" + shoename + "</strong><br /> shoe number <strong>" + shoenum + "</strong></li> <hr />"); $('#valuesmodal').modal('hide'); }); });
.container{ margin-top:30px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/> <div class="container"> <div class="col-sm-6"> <form> <div class="form-group"> <input type="text" class="form-control" value="first name" /> </div> <div class="form-group"> <input type="text" class="form-control" value="first name" /> </div> <button type="submit" class="btn btn-primary">submit</button> </form> </div> <div class="col-sm-6"> <div class="row"> <button class="btn btn-primary pull-right" data-toggle="modal" data-target="#valuesmodal"> add new pair </button> </div> <div id="addedvalues"> <ul> </ul> </div> </div> <!-- modal --> <div class="modal fade" id="valuesmodal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="mymodallabel">add shoe</h4> </div> <div class="modal-body"> <form> <div class="form-group"> <input type="text" class="form-control" placeholder="shoe name" /> </div> <div class="form-group"> <input type="text" class="form-control" placeholder="shoe number" /> </div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close</button> <button type="button" class="btn btn-primary" id="savevalue">save shoe</button> </div> </div> </div> </div> </div>
Comments
Post a Comment