0

I'm loading form into jquery-ui dialog using jquery.html() function and then Submitting doesn't work (alert doesnt show) - can someone tell me why?

here it is: http://jsfiddle.net/GMcev/11/

1
  • because it is type="submit", on clicking , it is submitting form
    – tusar
    Commented Jun 19, 2012 at 10:53

3 Answers 3

2

You need delegate event. Because your button is added to DOM after page load ie. dynamically, so you need something like following:

$('body').on('click', '.button', function() {
    alert('TEST!'); //it doesnt work            
});

DEMO

1
  • But you see, I'm loading some form into my ui dialog after click the link (after the dom is ready i think) and I want to submit it via ajax - will it work using one of yours methods?
    – pawel
    Commented Jun 19, 2012 at 10:59
2

Call

$(".button").click(function() {  
            alert('aaa');

in open action of dialog

$("#dialog").dialog({
        autoOpen: false,
        title: "contact",
        open: function() {
            $(".button").click(function() {
                alert('aaa');
            });
        }
    });
2

i suggest to put onclick in submit button

<input type='submit' name='submit' class='button' 
id='submit' value='Zapisz' onclick='dingDong()' />

http://jsfiddle.net/GexFz/1/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.