views:

50

answers:

2

Hi all, i am using jquery.simplemodal-1.1.1 and jquery-1.2.6.min to create a modal popup. this is my problem: i can display the windows, can insert values, fiels, ecc. i have 2 buttons, save and close. when i click on save button, it triggers an event that execute, from code behind, an store procedure that insert some dates on my db. the problem is, when i click on close button. I open the modal windows, don't do anything and click on cancel. Close the modal windows. i open again the modal windows, fill the fields and click on save. The program execute 2 times the event of the save button and then insert 2 times the same information on the DB. this is the javascript code what i am using:

$(document).ready( function()
{
  $("#nuovoT").click(function(ev) {
     ev.preventDefault();
     $("#TextBoxPrenot").val("");
     $("#msg").text("");
     //Open the 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 the 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 i am doing wrong???

thx in advance!!!

A: 

The problem is that your modalOpenAddCustomer routine is adding the click event onto the button each time the modal is opened. Therefore on the second time around, there are 2 click events on the same button.

Either: Initialise the click event outside the modalOpen... routine - ie within the (document).ready function.

Or: use 'one' instead of click:

dialog.data.find("#ButtonConferma").one('click', function(ev) {
Clicktricity
A: 

thx for you response. I have used dialog.data.find("#ButtonConferma").one('click', function(ev) { but it is not working anyway. can you give an example for initialize the click event outside the modalopen routine??
thx in advance