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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:33:45+00:00 2026-05-17T23:33:45+00:00

Edit: Originally I had a simple form Ajax script that wasn’t working, turns out

  • 0

Edit: Originally I had a simple form Ajax script that wasn’t working, turns out it was an extra bracket somewhere.

I have changed my question to the following:

1.)What I’d like to know is that how can I create an extra div to appear every time a value is sent? Of course, without changing the whole content inside the container and also preserving previous divs that were already created by the same mechanism.

2.)I’m going to cleanse input on the server. What would I echo server-side? Just the sanitized data or the sanitized data inside a div aka <div>$sanitizeddata</div>?

Scroll to see the html visual of what I mean.

Note: I didn’t want to start another question with the same code so I just edited my question accordingly after figuring out what was wrong with it. (My apologies to the previous repliers, but no one seemed to have caught the error! :P)

<script type="text/javascript">

$(document).ready(function()
{
    $("#testform").submit(function(e)
        {
            $.post("1.php", $(this).serialize(),function(data)
            {
             $('.result').html(data);});
              e.preventDefault();
                });
}); 
</script>

<div id="container" class="result">

<div><p>Some content 1</p></div>

<div><p>Some content 2</p></div>

<div><p>Some content 3</p></div>

//A new DIV is created with callback data (sanitized input) every time something is submitted
by the form.
<div></div>

//A new DIV is created with callback data (sanitized input) every time something is
submitted by the form while preserving previous DIVs already created by Javascript.
<div></div>

<div>
<form id="testform" action="1.php" method="post"> 
Number: <input type="text" name="num" /> 
<input type="submit" value="Submit Comment" /> 
</form>
</div>

</div>
  • 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-17T23:33:46+00:00Added an answer on May 17, 2026 at 11:33 pm

    So it seems you want the page to work in either js enable or not.

    Try this.

    If I was you, I would rethink my design I would break the code up into separate files. This is really a spaghetti design.

    <?php
    if (array_key_exists('js', $_POST)) {
        $js = $_POST['js'];
    
        if (array_key_exists('num', $_POST)) {
            $num = $_POST['num'];
            echo "<div>$num</div>";
            exit();
        }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>Untitled Document</title>
    
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
        <!--    <script type="text/javascript" src="./jquery.form.js"></script>-->
        <script type="text/javascript">
            $(document).ready(function() {
                $("#testform").submit(function() {
                    var serialized = $(this).serialize() + '&js=1';
    
                    $.post("1.php", serialized, function(data) {
                        $('.result').append(data);
                    });
    
                    $('#number_input').val('');
    
                    return false;
                });
            });
        </script>
    </head>
    
    <body>
    <div class="result">
        <?php
        session_start();
        if (array_key_exists('num', $_POST)) {
            $numbers = array();
            if(array_key_exists('numbers', $_SESSION)) {
                $numbers = $_SESSION['numbers'];
            }
            $numbers[] = $_POST['num'];
    
            foreach($numbers as $num) {
                echo "<div>$num</div>";
            }
    
            $_SESSION['numbers'] = $numbers;
        }
        else {
            $_SESSION['numbers'] = array();
        }
        ?>
    </div>
    <div>
        <form id="testform" action="1.php" method="post">
            <label for="number_input">Number: </label><input id="number_input" type="text" name="num"/>
            <input type="submit" value="Submit Comment"/>
        </form>
    </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: From another question I provided an answer that has links to a lot
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
I'm trying to single source a form page which can be in edit mode
I am currently working on a project that uses the Silverlight 3 SDK and
I have a very simple VS2005 deployment project that aims to install for all
I have an Eclipse project. It originally had a structure something like this: MyProj
Hi I'm building a very simple search system using ASP.NET MVC. I had it
I have a bunch of simple entity instances that I have serialized to a
EDIT: This question was exceptionally dumb and made me look like a script kiddie,
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code

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.