javascript - How to remove, validate adding dynamic form element and add to MySQL database using jQuery AJAX? -


so, found solution on how dynamically add form element using jquery , implement it, , works smoothly. way, made gis web app provide precise resident location , information of place. , stuck on how manipulate adding of resident's information members database.

my initial code:

js

 $(document).ready(function() {  $('#addrow').click(function() {  $('<div/>', {    'class': 'extraperson',    html: gethtml()  }).hide().appendto('#container').slidedown('slow');  });   $(document).on('click', "#removerow", function() {  var len = $('.extraperson').length;  if (len <= -1) {    $('.extraperson [name=firstname]').slideup('slow');    $('.extraperson [name=lastname]').slideup('slow');    $('.extraperson [name=gender]').slideup('slow');    $(this).fadeout('slow');  } else {    $('.extraperson [name=firstname' + (len - 1) + ']').slideup('slow');    $('.extraperson [name=lastname' + (len - 1) + ']').slideup('slow');    $('.extraperson [name=gender' + (len - 1) + ']').slideup('slow');    $(this).fadeout('slow');  }  });  });   function gethtml() {  var len = $('.extraperson').length;  var $html = $('.extrapersontemplate').clone();  $html.find('[name=firstname]')[0].name = "firstname" + len;  $html.find('[name=lastname]')[0].name = "lastname" + len;  $html.find('[name=gender]')[0].name = "gender" + len;  return $html.html();  } 

html

<div class="extrapersontemplate">   <div class="controls controls-row">     <input class="span3" placeholder="first name" type="text" name="firstname">     <input class="span3" placeholder="last name" type="text" name="lastname">     <select class="span2" name="gender">         <option value="male">male</option>         <option value="female">female</option>     </select>     <a href="#" id="removerow"><i class="icon-plus-sign icon-white"></i> remove row </a>     </div> </div> <div id="container"></div> <a href="#" id="addrow"><i class="icon-plus-sign icon-white"></i> add     family member</a> 

css

.extrapersontemplate {   display: none; } 

now, how validate members if user forgot enter value of member he/she clicked add row or 1 of inputs null in jquery???

and if submit form, how add inputted members mysql database?

any help, suggestions , ideas heavenly appreciated.

jsfiddle code above^


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -