Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to append the value for docid to the html form so that i can send it to the database table,

html code

<form id="upoadfile" class="form-horizontal">
                 
                  <div class="form-group row">
                    <label for="inputEmail3" class="col-sm-2 col-form-label"></label>
                     <div id="carnamediv"></div>
                    <div class="col-sm-10">
                      <input type="date" class="form-control" id="uploadate" name="uploadate">
                    </div>
                  </div>
                 
                 
                   <div class="form-group row">
                    <label for="inputEmail3" class="col-sm-2 col-form-label"></label>
                     <div id="carnamediv"></div>
                    <div class="col-sm-10">
                      <input type="file" class="form-control" id="docc" name="docc[]" multiple>
                    </div>
                  </div>
                  
                  
                 <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>       
              <button type="button" style="width:100%" id="docbtn" class="btn btn-primary">Post</button>
              <p style="color:blue;" id="posted"></p>
            </div> 
               
              </form>




function getCurrentApplicationDocuments (searchproductid=''){
       
       
      var loantable = $('#loandocstable').dataTable({
            
        "processing": true,
        "responsive": true,
        "serverSide":true,
         "destory":true,
         "paging":false,
         "info":false,
         "searching":false,
        "ajax": { 
            
            url:"serverside/getapplicationsdocs.php",
            "data": {
                    "loanid":searchproductid
            },
            type: 'post',  // method  , by default get
        
        },
        
        
        "columns": [
            
            {data:null,
                    render: function ( data, type, row ) {
                      return '<input type="checkbox" >';
                   }
            },
            
            {data: 'id',
              'createdCell':  function (td, cellData, rowData, row, col) {
                   $(td).attr('id', 'docid'); 
              }   
                
            },
            
            {data: 'documentpath'
                ,
              'createdCell':  function (td, cellData, rowData, row, col) {
                   $(td).attr('id', 'documentpath'); 
              }   
            }

            ]
            
            
          });
    
    
        
    }




json code,i want when i click editdocbtn,the value for docid to be append to the form


$(document).on("click","#editdocbtn",function (event) {

        event.preventDefault();
        event.stopPropagation();


         var doc = $(this).closest("tr").find("#docid").text();

                    var myform = document.getElementById('upoadfile');
                    var data = new FormData(myform);

                       data.append("id",doc);



   });


What I have tried:

have tried the code above but its not working
Posted
Updated 2-Nov-21 0:21am

1 solution

It's "not working" because you add the value to a new FormData instance, and then throw that instance away. Changes you make to that FormData instance will have no effect on the data submitted by the form.

Add a hidden input to the form with the correct name, and update that instead.

You'll also need a different way to identify the cells. You can't use the same ID for multiple elements in the same HTML document.
HTML
<form id="upoadfile" class="form-horizontal">
    <input type="hidden" name="id" />
    ...
JavaScript
...
{
    data: 'id',
    className: 'docid'
},
{
    data: 'documentpath',
    className: 'documentpath'
}
...
JavaScript
$(document).on("click","#editdocbtn",function (event) {
    event.preventDefault();
    event.stopPropagation();
    
    var doc = $(this).closest("tr").find(".docid").text();
    var myform = document.getElementById('upoadfile');
    var input = myform.querySelector("input[name='id']");
    input.value = doc;
});
 
Share this answer
 
Comments
Member 15069000 9-Nov-21 18:11pm    
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900