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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:12:12+00:00 2026-05-29T08:12:12+00:00

I have asked the first part of this question before, but with no answer

  • 0

I have asked the first part of this question before, but with no answer to it though. I managed to bind one event to the form, but to one of the forms nothing seems to work.

So, this is one of the forms I’m dynamically echoing in the HTML:

$regex = '/^.*(\d{4,4})_(\d{2,2})_(\d{2,2}).*$/';
$replacement = '$3 / $2 / $1';
$val = preg_replace($regex,$replacement,$name);             

$formReplacement = 'backup-$3-$2-$1';
$formID = preg_replace($regex,$formReplacement,$name);

$form = array(
        '<form name="rollback-form" id="' . $formID . '" class="rollback-form" method="post" action="#">',
            '<fieldset class="rollback-fields">',
                '<fieldset class="display-rollback-wrapper">',
                    '<label for="display-rollback" class="display-rollback-label">Backup</label>',
                    '<input type="text" name="display-rollback" class="display-rollback" value="' . $val . '" autocomplete="off" readonly="readonly" />',
                    '<input type="hidden" name="rollback_id" value="' . $id . '" />',
                '</fieldset>',
                '<fieldset class="rollback-wrapper">',
                    '<button type="submit" name="rollback" class="rollback">Rollback</button>',
                '</fieldset>',
            '</fieldset>',
        '</form>',
        '<div  id="' . $formID . '-message-handling" class="message-handling" class="message-handling"></div>'
    );
$form = implode("", $form);
echo $form;

In the above case, $name = $id = 'logindb_backup_2012_02_02.sql'.

And I’m applying the following jQuery function to the echoed form:

$('form.rollback-form').on('click', 'button.rollback',function() {

    var rollback_id = $(this).find('[name="rollback_id"]').val();
    var form_id = $(this).attr('id');

    console.log(rollback_id);
    console.log(form_id);

    $('.secondary-actions #'+form_id+'-message-handling').fadeOut();
    $.ajax({
        type:       'POST',
        url:        'assets/class/login/actions/rollback.php',
        dataType:   'json',
        data: {
            rollback:   rollback_id
        },
        success:function(data) {
            if(data.error === true) {
                $('.secondary-actions #'+form_id+'-message-handling').text(data.message).fadeIn();
                console.log(data.message);
                setTimeout(function () {
                    $('.secondary-actions #'+form_id+'-message-handling').fadeOut();
                }, 3500);
            }
                else {
                    $('.secondary-actions #'+form_id+'-message-handling').text(data.message).fadeIn();
                    console.log(data.message);
                    setTimeout(function () {
                        $('.secondary-actions #'+form_id+'-message-handling').fadeOut();
                    }, 3500);
                }
        },
        error:function(XMLHttpRequest,textStatus,errorThrown) {
            $('.secondary-actions #'+form_id+'-message-handling').text('Error | Check PHP log for information').fadeIn();
            console.log('Error | Check PHP log for information');
            setTimeout(function () {
                $('.secondary-actions #'+form_id+'-message-handling').fadeOut();
            }, 3500);
        }
    });
    return false;
});

This one works perfectly, I mean the 'click' event, it doesn’t send me to another page which would be the action of the form, it’s handled by the jQuery handler attached to the click event.

But the problem above is :

var rollback_id = $(this).find('[name="rollback_id"]').val();
var form_id = $(this).attr('id');

console.log(rollback_id);
console.log(form_id);

These two above output in the console undefined, why is that ? It should be something like rollback_id = 'backup/logindb_backup_2012_02_02.sql' and form_id = 'backup-02-02-2012'.

And the second part of my problem which I mentioned right in the head it’s the click event, it doesn’t work as the one for the above form does, when I click on the buttons, either of them, it just sends me to another page, the action of the form page which is #.

So here is the other form:

$form = array(
        '<form name="backup-form" class="backup-form" method="post" action="#">',
            '<fieldset class="backup-fields">',
                '<fieldset class="display-wrapper">',
                    '<label for="display" class="display-label">Backups</label>',
                    '<input type="text" name="display" class="display" value="' . $this->backups(false,true) . '" autocomplete="off" readonly="readonly" />',
                '</fieldset>',
                '<fieldset class="action-wrapper">',
                    '<button type="submit" name="clean" class="clean">Clean All</button>',
                    '<button type="submit" name="create" class="create">Create</button>',
                '</fieldset>',
            '</fieldset>',
        '</form>',
        '<div class="message-handling" class="message-handling"></div>'
    );
$form = implode("", $form);
echo $form;

In the form above $this->backups(false,true) it’s just a number, it’s not relevant to my question.

And here is the jQuery event triggers I’m trying to bind:

$('form.backup-form').on('click', 'button.clean',function() {
    console.log('Clean Button Pressed');
});


$('form.backup-form').on('click', 'button.create',function() {
    console.log('Create Button Pressed');
});

But these two don’t work at all. And I have tried with .delegate, .click, .submit but those don’t work either. So what could be the problem with these two ?

  • 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-29T08:12:13+00:00Added an answer on May 29, 2026 at 8:12 am

    Your code is this:

    var rollback_id = $(this).find('[name="rollback_id"]').val();
    var form_id = $(this).attr('id');
    

    Now, what is $(this) in this context? It’s button.rollback. Not the form.

    Do this instead:

    var form = $(this).closest('form');
    var rollback_id = form.find('[name="rollback_id"]').val();
    var form_id = form.attr('id');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have asked this question before but did not get the satisfied answer as
I have asked this before but I didn't get the question right so the
I have asked this question before and the problem was half solved in the
I have looked around here to see if somebody has asked this question before
This is probably a question that has been asked before, but I couldn't find
I know this type of question has been asked before, but I could not
I just asked a question about ordering but it was only the first part
i have asked a question about manytomanyfield here which i solved but now a
I have asked this question on Telerik forums with no reply so I'm turing
I asked this question earlier but I was very vague and a lot of

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.