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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:30:06+00:00 2026-05-23T22:30:06+00:00

We have a requirement where the web page displays all the records from joining

  • 0

We have a requirement where the web page displays all the records from joining few tables.
We have an “Add Button” – upon clicking the button, I have to display an popup window, where user will enter the necessary details. The popup will have two buttons Save and Cancel.

Clicking Save button, should validate the fields and if all validations are passed, then save the record to database else display the error messages in alert boxes.

Clicking Cancel button will close the popup window.

How do I create popup upon clicking add button?

  • 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-05-23T22:30:07+00:00Added an answer on May 23, 2026 at 10:30 pm

    You need to separate the things that are server-side (Rails, controllers, actions) and client-side (popups, JavaScript, sending requests).

    Your client-side actions (JavaScript code) should think about your Rails application as about some server, which returns some responses for some requests. From JavaScript’s point of view it is not important whether the server is running Rails or Smalltalk.

    The basic workflow for your popup may be:

    1) open a new window – This requires client-side activity of JavaScript. Use window.open function, or (I humbly consider this method a better one) create a new <div> and style it with CSS so it will cover (a nice effect is an half-opaque background: background: #ddf; opacity: 0.5;, through which you still see the content of the page).

    2) fill the window with an edit form – Here your client-side script should make an AJAX-like call (not necessarily real AJAX, since in this case a synchronic request may be sensible) to get the edit form from your Rails application. See this simplicated example:

    function fillPopupBody(popup) {
      var req = new XMLHttpRequest();
      req.open("GET","/something/partial_new_form.html",false); // Synchronic request!
      req.send(null);
      if( req.status == 200 ) {
        popup.innerHTML = req.responseText;
        return true;
      } else {
        popup.innerHTML = "<p class='error'>"+req.status+" ("+req.statusText+")</p>";
        return false;
      }
    }
    

    3) Prepare the form-returning action in your Rails application – (server-side) Usually this may be your new action of the given resource controller, but rendered without layout.

    An alternative approach would be to build the form by the JavaScript (without fetching it separately), or to include it always in the page – just hidden by default, so the JavaScript needs only to set its display property.

    4) Handle form submission – you probably want the user to stay on the same page, so you should intercept the form submission. Just add a handler to the “submit” event of the created form, build a request, post it, check the server response.

    The response will be returned by Rails, by your :create action. You may already have it ready, because the code created by ./script/rails generate scaffold is usually OK.

    If the response is 201 (created), you may close the popup (display: none) and update the page to display the new object – either refresh the whole page, or fetch only the changed parts.

    If the create action cannot create the object, by default the response code is 422 (unprocessable entity) and the content is the model errors object, rendered as JSON or XML. Just display the errors in the form (let your JavaScript set the innerHTML of some predefined element).


    That was the ‘manual’ way of doing the task. I have some aversion (hardly explainable 😉 to JavaScript libraries, and I prefer to work directly with DOM. You may find a lot of Rails helpers which will save you from writing JavaScript code. I guess that looking at the :remote => true parameter of form_for will be a good starting point.

    Also the jQuery documentation ( http://docs.jquery.com/Main_Page ) may be a good thing to read.

    Ending this long story, here are the short answers to your questions from the comment:

    How do i link controller actions from the popup?

    : By sending a HTTP request to the proper URL: “GET /users/1/notes/new”, “POST /user/1/notes”

    How do i close the popup?

    : By setting display: none if the popup is an element of the page, or by calling window.close() if your popup is a separate window.

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

Sidebar

Related Questions

I have a requirement to allow users to open word document from web page
I have a new requirement to have a button in my web page, and
Requirements: On a web page in our web application, we have a requirement to
I have a requirement to pass credentials from one Microsoft .NET Web Application to
I have an ambitious requirement for an asp.net 2.0 web page that contains a
I have a web page that has a requirement to allow users to paste
I have an asp.net web page with asp:button control. I need to show two
I have a requirement where i have to download file automatically from a web
I have the following requirement: On every request to my web page, regardless of
I have requirement of specifying web part connections in onet.xml. So when site is

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.