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
- $(document).on('click', '.savebtn', function () {
- var thisid=this.id;
- console.log(' id clicked='+thisid);
-
- var splitid=thisid.split('save');
- var onlyid=splitid[1];
-
- $('#onlyid').val(onlyid);
-
- var schoolid=$('#schoolid').val();
- var standardid=$('#standardid').val();
- var name=$('#subject'+onlyid).val();
- console.log('for save btn of row clicked subject name='+'#subject'+onlyid);
- console.log('row subject name='+'#subject'+onlyid);
- if($("#subject"+onlyid).length){
- console.log("The element #subject"+onlyid+" Element present.");
- console.log("The same element val="+$("#subject"+onlyid).val());
-
- }
-
- $('#subjectnewid'+onlyid).text('999999');
- console.log('save btn cicked >'+thisid+' call createsubjectmasterfill.php'+' schoolid '+schoolid+' standardid='+standardid+' name='+name );
- var url= "createsubjectmasterfill.php";
- data = {
- schoolid: schoolid,
- standardid: standardid,
- name: name
- }
- $('#subjectnewid'+onlyid).load(url,data, updatedropdownsubject ) ;
-
- });
Subject add Button Click script
- $(document).on('click', '.subjectadd', function () {
-
- console.log('class subjectadd clicked');
-
- $('.semestersubjectcontainer').each(
- function() {
- var thisid=this.id;
- console.log('this id='+thisid);
- var splitid=thisid.split('semestersubjectcontainer');
- var subid=splitid[1];
-
- console.log('for clone subid='+subid );
- var subline =$(".semestersubjectline" ).first().clone()
-
- $("#semestersubjectcontainer"+subid).append(subline);
- var noofsubjects=$('.semestersubjectline', $(this)).length;
- $('#semestersubjectcount'+subid).text(noofsubjects);
- console.log("number of subjects "+this.id+' '+$('.semestersubjectline', $(this)).length+' '+noofsubjects+' semestersubjectcount'+subid);
-
- //--------------------------------------------------------------//
-
- $('#semestersubjectcount'+subid).text(noofsubjects);
-
- //--------------------------------------------------------------//
-
- subline.attr("id","semestersubjectline"+subid );
- subline.find('.dropdown').attr("id","subjectddid"+subid+"x"+noofsubjects);;
- subline.find('.dropdown').attr("name","semestersubject"+"["+subid+"][]");
- subline.find($("[name*='subject']")).attr("name","subject"+subid+"x"+noofsubjects);;
- subline.find($("[name*='subject']")).attr("class","dropdown");;
- subline.find($("[name*='subject']")).attr("id","subject"+subid+"x"+noofsubjects);;
-
- subline.find($("#subjectddid"+subid+"x"+noofsubjects)).val('0');
- console.log( subline.find($("#subject"+subid+"x"+noofsubjects)).val());
-
- subline.find('.dropdown').attr("val","");;
- subline.find('.subject'+subid+"x"+noofsubjects).attr("val","");
- // subline.find($("[id*='subject']")).attr("id","subject"+subid+"x"+noofsubjects);;
-
- console.log(' find .savebtn set to '+"save"+subid+"x"+noofsubjects)
- subline.find('.savebtn').attr("id","save"+subid+"x"+noofsubjects); subline.find('.savebtn').attr("name","save"+subid+"x"+noofsubjects);
- subline.find('.subjectnewid').attr("id","subjectnewid"+subid+"x"+noofsubjects);;
- subline.find('.subjectnewid').attr("name","subjectnewid"+subid+"x"+noofsubjects);
-
- subline.find('.subjectdiv').attr("name","subjectnewid"+subid+"x"+noofsubjects);;
- subline.find('.subjectdiv').attr("id","subjectnewid"+subid+"x"+noofsubjects);;
-
-
- }
- );
-
- });