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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:39:30+00:00 2026-06-03T02:39:30+00:00

The code below simply submits a form via Ajax and appends the result from

  • 0

The code below simply submits a form via Ajax and appends the result from the addNewUser.php script into a small popup window.

//activate the signup submit button
$('#button_signup_submit').click(function() {

    document.getElementById("popup_signup").style.display = "none";
    document.getElementById("popup_signup_step_two").style.display = "block";
    //submit the form info via ajax to addNewUser.php
    $.ajax({
         type: "POST",
         url: "ajax/addNewUser.php",
         data: { 
            username: document.forms["form_signup"]["username"].value,
            password: document.forms["form_signup"]["password"].value
         },
         datatype: "html",
         success: function(data){

                    var jqObj = jQuery(data);
                    $('#popup_signup_step_two').append(jqObj)
                }
    });

});

I can get the above script to append the ajaxed html into the original webpage no problem… but when I go to use my second piece of code:

//activate the second signup page's return button
$('#return_to_signup_form_from_ajax_popup').click(function() {
    alert("HEY");
    //erase innerHtml of popup_signup_step_two
    document.getElementById("popup_signup_step_two").innerHTML = "";
    document.getElementById("popup_signup_step_two").style.display = "none";

    //show the original signup form again, should contain user's original values
    document.getElementById("popup_background").style.display = "block";
    document.getElementById("popup_login").style.display = "block";

});

…which is a jQuery snippet that works with the newly added html… nothing happens. That second piece of code applies when the user forgets to enter a username or password and they are given this message via ajax:

<p>Go <span id="return_to_signup_form_from_ajax_popup">back</span> and enter a username and password.</p>

I assume this all has something to do with the DOM? But ultimately I have no idea. If anybody could even point me in the direction of what to look for I would greatly appreciate it.

  • 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-03T02:39:31+00:00Added an answer on June 3, 2026 at 2:39 am

    Well, as long as you are sure the response is giving the proper html back – you should be doin alright. I would recommend changing your click handler to be a delegated handler instead – then you dont have to worry about if it was initialized before or after the ajax’d html was added to the live dom.

    EDIT: updated to use latest jquery on method. (http://api.jquery.com/on/)

    $('#containerElementThatAjaxdDataWillGoInto').on('click','#return_to_signup_form_from_ajax_popup', clickHandler );
    

    EDIT: Here is a further attempt at clarity.

    You are ajaxing in new html, and you are appending it to #popup_signup_step_two. Awesome. So this new html also has a button that needs to have a handler associated with it. To do this we need to delegate an event handler to #popup_signup_step_two so we can listen for all clicks on whatever element we want inside of that dom element.

    $('#popup_signup_step_two').on('click', '#return_to_signup_form_from_ajax_popup', function() {
        // do stuff here
    });
    

    Now that you have this setup (inside a document ready), any click to the element #return_to_signup_form_from_ajax_popup inside of #popup_signup_step_two will call your click handler function. Now inside your current click handler, you set #popup_signup_step_two to display = none. So, if you want to do that action again, you need to make sure you set the element to display block.

    I hope this helps more, if we are still missing eachother somewhere, this is the time to start getting things into a jsfiddle or give a link.

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

Sidebar

Related Questions

I have a data that looks like this . And my code below simply
Please see the form HTML code below <form method=post action=register> <div class=email> Email <input
The following code should update a hidden field on form submit but it simply
I'm trying a simple ajax test in Wordpress / Buddypress. The code below works
This is the PHP code: $html=<<<eod <div>Your current account balance is <span style=color:red>$$balance</span></div><br/> <form
I am trying to get the below code to call to a PHP file,
I created a sample form and code below to illustrate. I know i can
Here a sample use case: I request a simple form via an ajax request.
I am using below simple code to send mail using php. when i echo
A Submit button for a form located on my page triggers the code below,

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.