Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8530271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:13:18+00:00 2026-06-11T09:13:18+00:00

I have som problems regarding getting javascript to fire correctly inside dialog. Below is

  • 0

I have som problems regarding getting javascript to fire correctly inside dialog.

Below is the code from my scripts.js wich i currently use to load a dialog

function LoadDialog(url, title) {
    var DialogBox = $('<div class="dialog-container"></div>').dialog({ modal: true, autoOpen: false, resizeable: true }).dialog({ width: 500, height: 'auto' });
    DialogBox.html('<div class="ajax-load"><img src="/Content/loading.gif" alt="loading"></div>').dialog({ buttons: null, title: 'Loading..' });
    DialogBox.dialog('open').load(url, function () {
        DialogBox.dialog({ title: title, Buttons: null, position: 'center', close: function (ev, ui) { $(this).dialog("destroy"); } });
    });
}

$(function () {
    $('.as-dialog').click(function (e) { LoadDialog($(this).attr('href'), $(this).attr('title')); return false; });
});

Though no javascript code fires by default inside the dialog. For example i load a small form with unobtrusive validation into the dialog. No body, head etc, only a container div and the form itself. By default validation dont work and if i add event handlers for the form under script.js $(function(){}) it dont fire. If i add the following js references and codeblock to be loaded with the form it works with one problem:

<script src="/Scripts/libs/jquery.validate.min.js"></script>
            <script src="/Scripts/libs/jquery.validate.unobtrusive.js"></script>
            <script type="text/javascript">
                $(function () {
                    $('#form_Create').submit(function (e) {
                        e.preventDefault();
                    });
                });
            </script>

The non functioning regarding the code above is that validation will always work but if i open the dialog, close it, then open it again, the preventdefault will stop working and the form will post. Could this perhaps be a multiple load of script issue or something? Though since no ‘doc ready’ code works in dialog if placed in scripts.js (standard javascript functions work though) i dont really have another option.
Is there a better way to work with javascript inside dynamically loaded files or do i have to place the entire forms in the parent page to be able to work against them reliably?
Any input on how you should handle this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:13:19+00:00Added an answer on June 11, 2026 at 9:13 am

    The below method to open the dialog seems to have solved my primary problem:

    var Box = $('#dialog-container');
        if (Box.length === 0) {
            Box = $('<div id="dialog-container"></div>').appendTo('body');
        } else { Box.empty(); }
    

    Unsure atm if the empty() is needed because it seems that load does this anyway. But with this code i can open the dialogs how many times i like and the codeblock will still execute.

    Though my issue / question regarding if i have to live with calling some script files from the loaded pages or there is a better way of enabling scriptrunning from the parental loaded files. But atleast everything seems to work well now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to return som values I have selected in a jQuery UI Dialog
I have a very long price file from my wholesaler that I have som
I got som difficulties to output HTML-string code through XML.I have presented a example
I have a like the one below that does a minus from another select.
have a nice day. I got problem when trying to create an image from
I have some code that will trigger Code Analysis warning CA1063: CA1063 : Microsoft.Design
I am getting pretty frustrated, i have an tcp server running on my mac
I have this code: def method_a(self): command_line = 'somtoolbox GrowingSOM ' + som_prop_path subprocess.Popen(shlex.split(command_line))
I'm new to XNA and I'm building an Asteroids game. I have some problems
I have two tables from two different databases. For example: Table: Articles1 - Database:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.