javascript - jquery simple modal and insert on database -


i using jquery.simplemodal-1.1.1 , jquery-1.2.6.min create modal popup. problem: can display windows, can insert values, fiels, ecc. have 2 buttons, save , close. when click on save button, triggers event execute, code behind, store procedure insert dates on db. problem is, when click on close button. open modal windows, don't , click on cancel. close modal windows. open again modal windows, fill fields , click on save. program execute 2 times event of save button , insert 2 times same information on db. javascript code using:

$(document).ready( function() {   $("#nuovot").click(function(ev) {      ev.preventdefault();      $("#textboxprenot").val("");      $("#msg").text("");      //open popup container       $("#addtrasport").modal({  onopen: modalopenaddcustomer,  onclose: modalonclose,  persist: true,  containercss: ({ width: "500px", height: "275px", marginleft: "-250px" })       });   }); });  function modalopenaddcustomer(dialog) {   dialog.overlay.fadein('fast', function() {     dialog.container.fadein('fast', function() {       dialog.data.hide().slidedown('slow');     });   });   dialog.data.find(".modalheader span").html("titulo");  // if user clicks "yes"   dialog.data.find("#buttonconferma").click(function(ev) {  /*valida se si compila almeno uno dei due campi*/   $("#msg").val("");  if ( ($("#textboxtrasp").val() == '') ){    $("#msg").append("* devi immetere il nome del trasportatore <br/>");   ev.preventdefault;  return false;   }   else{   }   $.modal.close();   $("#buttonhiddenaddcustomer").click();   });   dialog.data.find("#buttoncancel").click(function(ev) {      ev.preventdefault();      $.modal.close();      return false;   }); } 

what doing wrong???

thx in advance!!!

the problem modalopenaddcustomer routine adding click event onto button each time modal opened. therefore on second time around, there 2 click events on same button.

either: initialise click event outside modalopen... routine - ie within (document).ready function.

or: use 'one' instead of click:

dialog.data.find("#buttonconferma").one('click', function(ev) { 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -