NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

$(document).ready(function(){

//Changing Ward
$("#change_ward").on("change",function(){
var ward = $(this).val();
console.log("Switching to ward: " + ward);
document.location = "change_ward.php?ward="+ward+"&redirect=data-mgmt.php";
});


//When + is clicked to add a member


$("#members").on("click","tr td a.add-circle",function(){
console.log("Adding a new Member");
var newChild = $("#newChild").html();
$("#members").append("<tr>"+newChild+"</tr>");
return false;

});

//When - is added to delete a member
$("#members").on("click","tr td a.remove-circle",function(){
if(confirm("Sure to delete this member? You will delete this permanently.")){
console.log("Removing a new Member");
$(this).parent().parent().remove();
}
return false;

});



$("#save-data").on("click", function(){
console.log("No of Childs:" + ($("table#members tr").length - 2));

$("#message").slideDown(400);
$("#message div").html("<h1><img src='../img/load.gif' style='width:30px;height:30px'/> Saving, Please Wait...</h1>");


vdc_code = $("input[name='vdc_code']").val();
ward = $("input[name='ward']").val();
family_code = $("input[name='family_code']").val();

//Step A : Save Family Data
$("#message div").append("<h6>Saving Family Data...</h6>");


//First Of all, Let us get all the input values:
var family_controls = [
"vdc_code","ward","family_code","family_head",
"street","surname","caste","sub_caste","religion","family_type","mother_tongue",
"home_owner","house_stay","property_male","property_female","property_other","property_dual",
"sch_time_primary","sch_time_uprimary","sch_time_secondary","sch_time_usecondary","sch_time_campus","sch_time_private",
"cow","ox","buffalo","he_buffalo","goat","he_goat","sheep","he_sheep","chicken","duck","pigeon","other_animals",
"house_roof","house_wall","house_toilet","house_water","power",
"cook_elect","cook_wood","cook_gas","cook_oil","cook_other",
"tech_phone","tech_tv","tech_internet","tech_computer","tech_fax","tech_fridge","tech_other",
"tech_panighatta","tech_gobargyas","tech_gobargyas_toilet","tech_mill","tech_sudhar_chulo","tech_dhiki","tech_janto", "eq_effect"
];

var family_values = [];
for(var i = 0; i<family_controls.length; i++){
//Pushing the values

if($("[name="+family_controls[i]+"]").attr("type") == "checkbox" || $("[name="+family_controls[i]+"]").attr("type") == "radio"){
var value_to_push = $("[name="+family_controls[i]+"]:checked").val();
if(!value_to_push){ //If not selected
value_to_push = "0";
}
} else {
var value_to_push = $("[name="+family_controls[i]+"]").last().val();

}

family_values.push(value_to_push);


}


var query = "REPLACE INTO `family` (`" + family_controls.join("`,`") + "`) VALUES ('" + family_values.join("','")+"')";

console.log(query);

$.ajax({
url: "../inc/sql.php?query="+query,
cache: false,
beforeSend: function( xhr ) {
xhr.overrideMimeType( "text/plain; charset=utf-8" );
},
success: function(data){
if(data >= 1){
$("#message div").append("<h6>&check; Family Data Saved.</h6>");
} else {
console.log(data);
}

}
});



//Step B: Save Personal Data
var no_of_members = $("table#members tr").length - 2;
$("#message div").append("<h6>Saving Indiviual Data("+no_of_members+")...</h6>");

//For later
var saved = true;
//First Deleting Family Members
var query = "DELETE FROM `individual` WHERE `family_code` = '"+$("input[name=family_code]").val()+"'";
console.log(query);

$.ajax({
url: "../inc/sql.php?query="+query,
cache: false,

beforeSend: function( xhr ) {
xhr.overrideMimeType( "text/plain; charset=utf-8" );
},
success: function(data){
if(data >= 0){
console.log("Deleted older individuals...");
//Using For Loop for each data



for(var m = 1; m <= no_of_members; m++){ //Using 1-Index because first is empty
//First Of all, Let us get all the input values:
var individual_controls = [
"name","surname","father","mother","birthplace","gender","marital_status","spouse","religion","caste",
"birthday","education","training","disability","stay_status",
"employment","social_fund","annual_income","mobile","internet"
];




var individual_values = [];
for(var i = 0; i<individual_controls.length; i++){
//Pushing the values

var thisInput = $("[name=personal-"+individual_controls[i]+"]")[m];

if(thisInput.type == "checkbox"){
if(thisInput.checked){
value_to_push = "1";
} else {
value_to_push = "0";
}

} else {
var value_to_push = thisInput.value;
}

individual_values.push(value_to_push);


}


var query = "INSERT INTO `individual` (`vdc_code`,`ward`,`family_code`,`"+individual_controls.join("`,`") + "`) VALUES ('" +vdc_code+"','"+ward+"','"+family_code+"','"+individual_values.join("','")+"')";

console.log(query);

$.ajax({
url: "../inc/sql.php?query="+query,
cache: false,
beforeSend: function( xhr ) {
xhr.overrideMimeType( "text/plain; charset=utf-8" );
},
success: function(data){
if(data == 0){
saved = false;
}

}
});

} //For Loop of Individual ends






}

}
});


if(saved){
$("#message div").append("<h6>&check; Indiviual Data Saved.</h6>");
$("#message div").html("<h5>Successfully Saved!</h5>");
$("#message div").append("<a class='btn btn-success' href='data-mgmt.php'>Add New Data</a>");
$("#message div").append("<a class='btn btn-pimary' href='data-mgmt.php?family_code="+family_code+"'>Edit Again</a>");
$("#message div").append("<a class='btn btn-warning' href='family_all.php'>See All</a>");
} else {
$("#message div").append("<h6>&cross; Error in saving personal data. Check again!</h6>");
}



return false;


});








});
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.