how to open jquery ui dialog automatically when the page loads?

10,430

use autoOpen: true, to make it open directly when page loads

Share:
10,430

Related videos on Youtube

rgksugan
Author by

rgksugan

Updated on June 04, 2022

Comments

  • rgksugan
    rgksugan almost 2 years

    I need my dialog to open when the page is loaded automatically. What is the way to do it using jquery. Without any user interaction to open it.

    I tried this code but it dint work

    <html>
        <head>
            <link rel="stylesheet" type="text/css" href="css/style.css" media="screen,projection" />
            <script type="text/javascript" src="script/jquery-1.4.2.min.js"></script>
            <link type="text/css" href="css/jquery-ui-1.8.1.custom.css" rel="stylesheet" />
            <script type="text/javascript" src="script/jquery-ui-1.8.1.custom.min.js"></script>
            <script type="text/javaScript">
                $(function(){
                    $('#dialog').dialog({
                        autoOpen: true,
                        width: 600,
                        buttons: {
                            "Ok": function() {
                                $(this).dialog("close");
                            }
                        }
                    });
                });
            </script>
        </head>
        <%
                    if (session.getAttribute("user") == null) {
                        response.sendRedirect("index.jsp");
                    }
        %>
        <body>
            <div id="wrap">
                <div id="header">
                </div>
    
                <div id="leftside">
                    <h2 class="hide">Sample menu:</h2>
                    <ul class="avmenu">
                        <li><a href="dashboard.jsp" class="current">Dash Board</a></li>
                        <li><a href="createpoll.jsp">Create Poll</a></li>
                        <li><a href="availpoll.jsp">Vote Poll</a></li>
                        <li><a href="viewresults.jsp">View Results</a></li>
                        <li><a href="underconstruction.jsp">Settings</a></li>
                        <li><a href="logout">Log Out</a></li>
                    </ul>
                </div>
    
                <div id="contentwide">
                    <%@page import="com.jSurvey.entity.question" %>
                    <%@page import="com.jSurvey.controller.questionJpaController" %>
                    <%
                      //code to write data to database
                    %>
                    <div id="dialog"><p>Data Added successfully</p></div>
                </div>
                <div id="footer">
                </div>
            </div>
        </body>
    </html>
    

    Please help.

  • Matt
    Matt almost 14 years
    $(function () { /* Your dialog code */ }) is equivalent to $(document).ready(function () { /* Your dialog code */ }
  • edl
    edl almost 14 years
    Yeah, I just realized that when I looked into a little more. Just another case of the blind leading the blind. :)