I wish I new how to even give a better title. But I have no idea even in which ballpark my problem is.
I'm trying to build something that allows me to ask "you really wanna?" after a user sends or saves a form. Here's my fiddle: http://jsfiddle.net/chrystalingus/zXUQ4/
$('.confirm_this').click(function(e){
e.preventDefault();
var modal_markup = '<div id="modal_confirm"></div>';
$('body').append($(modal_markup));
var send_button = $(this);
var formular = send_button.parent();
var formular_width = formular.outerWidth();
var formular_height = formular.outerHeight();
var reset_button_markup = '<input id="reset_button" type="reset" value="No">';
$(reset_button_markup).insertAfter(send_button);
var reset_button = $('#reset_button');
var orig_send_value = send_button.attr('value');
var form_marker_markup = '<div id="form_marker"></div>'; // placeholder for the form which temporarily goes into the modal overlay (and to find it's original location later)
$(form_marker_markup).insertAfter(formular);
var form_marker = $('#form_marker');
form_marker.css({
'width': formular_width+'px',
'height': formular_height+'px'
});
var modal = $('#modal_confirm');
send_button.unbind();
formular.children().hide();
send_button.attr('value', 'Yes').show();
reset_button.show();
formular.appendTo(modal);
modal.show();
reset_button.click(function(e){
e.preventDefault();
formular.insertBefore(form_marker);
form_marker.remove();
modal.remove();
reset_button.unbind().remove();
send_button.attr('value', orig_send_value).unbind();
formular.children().show();
confirm();
});
});
This is supposed to work for any kind of form - no matter what the input types, the layout etc.
I'm fairly new to this and realize my jquery code is rather clumsy and crude - but should nonetheless work. So basically I'm trying to catch and prevent the click on the button class="confirm_this". The entire (hidden) form is being put up again in a modal overlay and the former "Send" button is now the "Yes" button.
It seems to work fine and if I had only one form on the page I guess the problem would never occur. But as soon as I have 2 forms on the page this happens: I click send on form A - modal - "no" - repeat - repeat then I click send on form B - modal - (all fine so far) - "no" ... Result: however often I repeated the process for form A - that's how many "No" buttons appear in the page next to form B. Also I have as many before body end. This happens only in browser, in jsfiddle I get an alert "undefined" but I have no clue what is not yet defined... Chrome console gives nothing at all.
Thanx for your help...