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 8018123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:03:20+00:00 2026-06-04T21:03:20+00:00

Below is the Html button and javascript function I have which closes a modal

  • 0

Below is the Html button and javascript function I have which closes a modal window:

<button type="button" id="close" onclick="return parent.closewindow();">Close</button>

function closewindow() {     
    $.modal.close(); 
    return false;
} 

Now the code above does close the modal window which is fine.

But I want to know how to write the code by using this function and html button below:

<button type='button' class='add'>Add</button>



  $(document).on('click', '.add', function(){ 

        $.modal.close(); ;
        return true;
    });

The above code does not close the modal window, why is this? Both these codes are on the same page by the way.

I am using simplemodal developed by eric martin

UPDATE:

Below is full code (QandATable2.php) but it is still not closing modal window when clicking on “Add” button:

 $(document).ready(function(){
      $('.add').on('click', function(){ 
//close modal window when user clicks on "Add" button (not working)
           $.modal.close();
      });
 });

function plusbutton() { 
    // Display an external page using an iframe 
    var src = "previousquestions.php"; 
    $.modal('<iframe src="' + src + '" style="border:0;width:100%;height:100%;">');

//Opens modal window and displays an iframe which contains content from another php script
    return false;
} 


function closewindow() {     

    $.modal.close(); 
    return false;
//closes modal window when user clicks on "Close" button and this works fines
} 

...HTML

    <table id="plus" align="center">
    <tr>
    <th>
    <a onclick="return plusbutton();">
    <img src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage" name="plusbuttonrow"/>
    </a>
    <span id="plussignmsg">(Click Plus Sign to look <br/> up Previous Questions)</span>
    </th>
    </tr>
    </table>

Below is the full code which displays all of the information that goes into the modal window (this is in previousquestions.php script). This includes both “Add” and “Close” buttons:

<div id="previouslink">
<button type="button" id="close" onclick="return parent.closewindow();">Close</button>      
</div>

<?php 


      $output = "";

        while ($questionrow = mysql_fetch_assoc($questionresult)) {
$output .= "
<table>
      <tr>
      <td id='addtd'><button type='button' class='add'>Add</button></td>
      </tr>";
        }
        $output .= "        </table>";

        echo $output;

?> 
  • 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-04T21:03:22+00:00Added an answer on June 4, 2026 at 9:03 pm

    From what I remember from the comments, you wanted to close the modal when clicking in an add button inside the modal right?

     $(document).ready(function(){
          $('.add').on('click', function(){ 
               $.modal.close();
          });
     });
    

    ​
    I made your first example (before your question edit) work, take a look at this JSFiddle.

    Be careful with the order you show/hide elements and wrap your function inside the $(document).ready() to prevent the code execution before the DOM is loaded.

    If you don’t manage to adapt your page to work similarly to my fiddle, you should post more from your page’s code as there’d probably be something causing the plugin to don’t work properly (or switch to another modal plugin).

    edit: You’re using an iframe, that’s why you can’t access the parent window’s defined functions from the iframe‘s scope directly. You could try using the window.opener to access your parent window’s scoped functions, or, to solve all and any window scope problem:

    Replace

    $.modal('<iframe src="' + src + '" style="border:0;width:100%;height:100%;">');
    

    With

    $.modal('<div id="modal" style="border:0;width:100%;height:100%;">');
    $('#modal').load(src);
    

    This will load content to the div dynamically through Ajax, which is a better approach and resolves any window scope problems which you were facing.

    Either that or switch to a modal plugin which supports loading pages directly to it, for instance, colorbox.

    EDIT

    Now with your full code it was easy to find a solution, simply add onclick='parent.closewindow();' to your add button in your PHP:

    <td id='addtd'><button type='button' class='add' onclick='parent.closewindow();'>Add</button></td>
    

    This way, it’ll re-use the existing closewindow function and discard the .on binding for the .add buttons. 🙂

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

Sidebar

Related Questions

I have a script, see below: Index page: jQuery script <script type=text/javascript> $(document).ready(function(){ $(#loadmorebutton).click(function
I have below html code in my aspx. <input type=hidden id=medicalLink value='<a href=/forms/contactus.aspx >Contact
i have my code(html/javascript) here which allows user to input the size and color
I have 3 little questions about eric martin's modal window which I can't seem
I have a HTML page in which I have a button; pressing that button
I am using the HTML button tag but the style mentioned below should only
I have below html code in one of the opensource project. <form action=/wiki/bin/view/Main/Search> <div
I am having issues with the below HTML when resizing the window; 1: Right
I have a form with the following HTML below: <form id=course_edit_form name=course_form action=/courses/save method=post>
Suppose I have 1) a HTML document. 2) This HTML document loads Javascript file

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.