i have created 2 textboxes, 2 dropdowns inside datatable dynamically. have button 'add'. when clicked, datatable dynamic control created. first dropdown's value filled external control. first dropdown contains projectid , projectname. second dropdwon should contain member names associated selected project.
the thing i've unique id both dropdowns. like, if 2 rows added, first dropdown project have id "project_0", second project dropdown have "project_1", similarly, first member dropdown have id "who_0", second have "who_2". how happens.
my requirement is, when first project dropdown selected project, first member dropdown should have member names associated project.
my problem is, don't know how proceed, ie how retrieve value first project dropdown, send db , fetch value.
this how i've tried:
$("#customerid").off("click").on("click",function(){ if($(this).val()=="0"){ projectid = []; } else{ $.ajax({ method: "get", url: "../api/momapi.php?action=getprojectsbycustomerid", data: {"customerid":$(this).val()}, success: function(data) { console.log(data); projectid = $.parsejson(data); }, error:function( jqxhr, textstatus, errorthrown ){ alert( errorthrown ); } }); } }); momactivity = $("#momactivity").datatable({ "sdom": "t", "ajax":{ "url": "../api/momapi.php?action=getmombyid", "type": "get", "data": {"momid": <?php echo $_get["momid"]; ?>} }, "destroy": true, "ordering": false, "columns": [ { "title": "project", "data": "projectid", "render": function(data, type, row){ return '<select class="form-control selectprojectid" id="project_'+a+'" name="projectid[]" valueid='+ data +'></select>'; } }, { "title": "what", "data": "what", "render": function(data, type, row){ return '<input type="text" class="form-control" name="what[]" value="'+ data +'">'; } }, { "title": "who", "data": "who", "render": function(data, type, row){ return '<select class="form-control selectwho" name="who[]" id="who_'+c+'" value="'+ data +'">'; } }, { "title": "when", "data": "when", "render": function(data, type, row){ return '<input type="text" class="form-control whendate" name="when[]" value="'+ moment(data).format("dd-mm-yyyy") +'">'; } }, { "title": "...", "render": function(data, type, row){ return '<input type="button" class="btn btn-default btn-sm remove" value="remove" name="remove" id="remove">'; } } ], "drawcallback": function(settings){ $(".selectprojectid").each(function(){ if($(this).find("option").length == 0){ $(this).fillselect(projectid,"projectid","projectname",0,1).val($(this).attr("valueid")); } }) $(".selectwho").each(function(){ if($(this).find("option").length == 0){ $(this).fillselect(momuserid, "userid", "username", 0,1).val($(this).attr("valueid")); } }); }, "rowcallback": function( row, data, index ) { $('td > input.remove', row).off("click").on("click",function(){ momactivity.row($(this).parents('tr')).remove().draw(); }); $('td > input.whendate', row).datetimepicker({ format: "dd-mm-yyyy" }); }, "fncreatedrow": function(nrow, adata, idisplayindex, idisplayindexfull){ = + 1; c = c + 1; } }); if($("#customerid").val()=="0"){ mynotif.show("select customer","warning"); } else{ var selectedprojectid =$("#momactivity").find('tr:last-child').find('.selectprojectid').val(); if(typeof selectedprojectid == 'undefined') { selectedprojectid = ""; momactivity.row.add({"projectid":selectedprojectid,"what":"","who":"","when":""}).draw(); } else if(selectedprojectid == "") { mynotif.show("select project","warning"); } else{ alert(selectedprojectid); momactivity.row.add({"projectid":selectedprojectid,"what":"","who":"","when":""}).draw(); } }
ultimately, i've retrieve value .selectprojectid, send db. how can that?
Comments
Post a Comment