Cannot get value of input dynamically created / added by program or Jquery using clone

Cannot get value of input dynamically created / added by program or Jquery using clone





Dear Sir
 
Working on project were need to add subjects dynamically using Jquery CLONE as follow.

for existing rows everything runs perfectly ok 
but
for programatically added row
cannot get value entered in input using JQUERY


script when save (savebtn) is clicked
works fine for existing rows
  1. $(document).on('click', '.savebtn', function ()  {  
  2. var thisid=this.id;
  3. console.log(' id clicked='+thisid);
  4. var splitid=thisid.split('save');
  5. var onlyid=splitid[1];
  6. $('#onlyid').val(onlyid);
  7. var schoolid=$('#schoolid').val();
  8. var standardid=$('#standardid').val();  
  9.     var name=$('#subject'+onlyid).val();
  10. console.log('for save btn of row clicked subject name='+'#subject'+onlyid);
  11. console.log('row subject name='+'#subject'+onlyid);
  12. if($("#subject"+onlyid).length){

  13.        console.log("The element  #subject"+onlyid+" Element present.");
  14. console.log("The same element val="+$("#subject"+onlyid).val());
  15.         
  16.         }
  17.  
  18.    $('#subjectnewid'+onlyid).text('999999');
  19.     console.log('save btn cicked   >'+thisid+' call createsubjectmasterfill.php'+' schoolid '+schoolid+' standardid='+standardid+' name='+name );
  20. var url= "createsubjectmasterfill.php";
  21. data = {
  22. schoolid:   schoolid,
  23. standardid: standardid,
  24. name: name 
  25. }
  26. $('#subjectnewid'+onlyid).load(url,data, updatedropdownsubject )  ;
  27.  
  28.    });

Subject add Button Click script

  1. $(document).on('click', '.subjectadd', function ()  {
  2.  
  3.  console.log('class subjectadd clicked');
  4.  
  5.  $('.semestersubjectcontainer').each(
  6.   function() {
  7.   var  thisid=this.id;
  8.   console.log('this id='+thisid);
  9.   var splitid=thisid.split('semestersubjectcontainer');
  10.   var subid=splitid[1];

  11.  

  12.   console.log('for clone subid='+subid );
  13.   var subline =$(".semestersubjectline" ).first().clone()
  14.   
  15.    $("#semestersubjectcontainer"+subid).append(subline);
  16. var noofsubjects=$('.semestersubjectline', $(this)).length;
  17. $('#semestersubjectcount'+subid).text(noofsubjects);
  18.      console.log("number of subjects "+this.id+'  '+$('.semestersubjectline', $(this)).length+' '+noofsubjects+' semestersubjectcount'+subid); 
  19.   
  20. //--------------------------------------------------------------//  
  21.   
  22. $('#semestersubjectcount'+subid).text(noofsubjects);
  23.   
  24. //--------------------------------------------------------------//   
  25.   
  26. subline.attr("id","semestersubjectline"+subid );
  27. subline.find('.dropdown').attr("id","subjectddid"+subid+"x"+noofsubjects);;
  28. subline.find('.dropdown').attr("name","semestersubject"+"["+subid+"][]");
  29. subline.find($("[name*='subject']")).attr("name","subject"+subid+"x"+noofsubjects);;
  30. subline.find($("[name*='subject']")).attr("class","dropdown");; 
  31.   subline.find($("[name*='subject']")).attr("id","subject"+subid+"x"+noofsubjects);; 
  32.   
  33.      subline.find($("#subjectddid"+subid+"x"+noofsubjects)).val('0');
  34. console.log( subline.find($("#subject"+subid+"x"+noofsubjects)).val());
  35.   
  36.   subline.find('.dropdown').attr("val","");; 
  37.    subline.find('.subject'+subid+"x"+noofsubjects).attr("val",""); 
  38. // subline.find($("[id*='subject']")).attr("id","subject"+subid+"x"+noofsubjects);;
  39.   
  40.   console.log(' find .savebtn  set to '+"save"+subid+"x"+noofsubjects)
  41.   subline.find('.savebtn').attr("id","save"+subid+"x"+noofsubjects); subline.find('.savebtn').attr("name","save"+subid+"x"+noofsubjects);
  42.   subline.find('.subjectnewid').attr("id","subjectnewid"+subid+"x"+noofsubjects);;
  43.   subline.find('.subjectnewid').attr("name","subjectnewid"+subid+"x"+noofsubjects);
  44.   
  45.   subline.find('.subjectdiv').attr("name","subjectnewid"+subid+"x"+noofsubjects);;
  46.   subline.find('.subjectdiv').attr("id","subjectnewid"+subid+"x"+noofsubjects);;
  47.   
  48.   
  49.   }
  50. );
  51.    
  52.   });
    • Topic Participants

    • vikas