0

I`ve the following code. There is a dialog with terms loaded and it shows on a form submit. Help me please to submit the form by the agree button in a dialog.

$(".terms").dialog({
  autoOpen: false,
  modal: true,
  height: 400,
  width: 500,
  buttons: {
    "I agree": function() {
      return $("#new_user").submit();
    },
    "Don`t agree - Exit": function() {
      return $(this).dialog("close");
    }
  }
});

$("#new_user").submit(function(e) {
  e.preventDefault();
  return $(".terms").dialog("open");
});

Thanks!

5
  • 1
    "Help me please to disable prevent on it and submit it." WHAT?! I don't know what kind of language it is, but it's definitely not English! Commented Jun 8, 2012 at 14:05
  • Ok sorry help me just to submit it using button ;) Commented Jun 8, 2012 at 14:07
  • Using which button? The submit button or another button? Commented Jun 8, 2012 at 14:08
  • Sorry i dont know if it's just me, or is your code doing an infinite loop on i agree? every time you submit the same dialog will appear again? Commented Jun 8, 2012 at 14:11
  • First the form prevents from submitting and opens a dialog. Then i want by clicking on agree button in dialog the form to be submitted. Commented Jun 8, 2012 at 14:17

3 Answers 3

1

It's not clear exaqctly what you want but maybe this helps. To prevent the default action you must be inside the submit function

$("#new_user").submit(function(e) {
    e.preventDefault();    
    $(".terms").dialog("open");
});
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, ive just misconverted it from .coffee thats why there was a mistake
1
buttons: {
    "I agree": function() {
      return $("#new_user").unbind("submit").submit();
    },
    "Don`t agree - Exit": function() {
      return $(this).dialog("close");
    }

.unbind("submit").submit(); Will help to submit the form in this case.

Comments

0
>$("#new_user").submit(function(e) {
});

You have a totally empty function

e.preventDefault();

Then proceed refer to something which is out of scope (in scope only in the function block)

$(".terms").dialog("open");

Then randomly open a dialog.

Place the two lines within the function block and return false and you should be a step further.

The next problem is that you're pretty much looping around by calling .submit on the same element you've just popped the terms dialog from. It's all a bit confused.

You probably need a "submit" button which pops the dialog which then calls submit on the form I'm guessing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.