javascript - AJAX post not sending value from form data -


i have weird situation, have created ajax post static value , it's work fine. tried ajax post dynamic value html input doesn't work. if tried insert value="1" post 1 php. can take code ?

<script>  $(document).ready(function () {    $('#unggah<?php echo $mhs?>').submit(function (event) {   var formdata = {             'jmlmhs': $('input[name=jmlmhs]').val(),             'mulaikul': $('input[name=mulaikul]').val(),             'akhirkul': $('input[name=akhirkul]').val()         };     $.ajax({             type: 'post',             url: '<?=base_url()?>operator_pt/unggah/<?php echo $proses.'_'.$cl?>',             data: formdata,             datatype: 'json',             encode: true         })            event.preventdefault();       });  }); </script> 

html

<form action="<?=base_url()?>operator_pt/unggah/<?php echo $proses.'_'.$cl?>" method="post" role="form" id="unggah<?php echo $mhs?>"> <label for="jmlmhs">jumlah mahasiswa diterima</label> <div id="jmlmhs" class="form-group"> <input type="text" class="form-control" id="jmlmhs" name="jmlmhs" value="">        </div>  <label for="datepicker">tanggal mulai kuliah</label> <div class="input-group date" data-provide="datepicker" id="datepicker">     <input type="text" class="form-control" name="mulaikul" value="">     <div class="input-group-addon">         <span class="glyphicon glyphicon-th"></span>     </div> </div>  <label for="datepicker1">tanggal akhir kuliah</label> <div class="input-group date" data-provide="datepicker" id="datepicker1">     <input type="text" class="form-control" name="akhirkul" value="">     <div class="input-group-addon">         <span class="glyphicon glyphicon-th"></span>     </div> </div>   <button type="submit" id="button1<?php echo $mhs?>" class="btn btn-primary" ><?php echo $tombol ?></button>  </form> 

you need put quotes around name in css selector:

 var formdata = {     'jmlmhs': $('input[name="jmlmhs"]').val(),     'mulaikul': $('input[name="mulaikul"]').val(),     'akhirkul': $('input[name="akhirkul"]').val()  }; 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -