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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:01:41+00:00 2026-06-16T11:01:41+00:00

I have the following form (below) which has a hidden input tag. On form

  • 0

I have the following form (below) which has a hidden input tag. On form submission and response back I want to change the name of that hidden inputs name to have a value of “__REMOVE__”. Then on submission of the response of the form again I want it to go back to “__ADD__”, and so on. The code however is not working for me, the name=”__ADD__” never changes on the form. I’m very new to jQuery so please excuse my ignorance. Note, the value of __BRONZE__ should never change – it is a requirement of the backend PHP that the name changes.

Form:

<form action="cart.php" method="post" class="cart-ajax">
    <input type="hidden" name="__ADD__" value="__BRONZE__" />
    <br><button type="submit" class="add-more-top dark cart-button-eight">Add to Cart</button>
    <div class="cart-ajax-response"></div>
</form>

jQuery:

$(document).ready(function() {

// code here snipped out to keep this question short

    // Shopping Cart Form
    $("form.cart-ajax").submit(function(e) {
            e.preventDefault();
            var form = $(this);

            // update the submit buttons text on form submission
            if(form.find('input:hidden').attr('name', '__ADD__'))
            {
                    form.find('button:submit').html('Adding...');
            }
            else if(form.find('input:hidden').attr('name', '__REMOVE__'))
            {
                    form.find('button:submit').html('Removing...');
            }

            $.post(form.attr('action'), form.serialize(),
                    function(data) {

                            // update the submit buttons text after successful response 
                            // update the hidden form field with the opposite of the current value
                            if(form.find('input:hidden').attr('name') == '__ADD__')
                            {
                                    form.find('button:submit').html('Remove');
                                    form.find('input:hidden').attr('name', '__REMOVE__');
                            }
                            else if(form.find('input:hidden').attr('name') == '__REMOVE__')
                            {
                                    form.find('button:submit').html('Add');
                                    form.find('input:hidden').attr('name', '__ADD__');
                            }

                            // do something with the returned data - used in cart-ajax-response div
                            form.find('.cart-ajax-response').empty().html(data.aResults[0]);

                    }, 'json');
    });
}); // <-- document ready
  • 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-16T11:01:42+00:00Added an answer on June 16, 2026 at 11:01 am
    if(form.find('input:hidden').attr('name', '__ADD__'))
    

    isn’t doing what you think. You’re actually setting that field’s name not asking if it exists.

    Use

    if(form.find('input[name="__ADD__"]').length)
    

    and note .length gets you an integer. Without it you’ll be returned an object, which is true even if its length is 0.

    However, take a look at this http://jsfiddle.net/3xTfX/2/ – same thing, less code

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

Sidebar

Related Questions

I have a form with the following HTML below: <form id=course_edit_form name=course_form action=/courses/save method=post>
I have the following form: echo $this->Form->input('Person.name'); echo $this->Form->input('Person.phone'); echo $this->Form->input('Person.email'); echo $this->Form->input('Message.0.plainmsg'); echo
i have the following form <form action=ManageLink method=post> <input name=artistName type=text/> <input name=songName type=text/>
I have the following form : <input name=linkColor type=text id=colorpickerField0 > <input name=linkColor type=text
I have just started to develop the form below and I have the following
I have the following form, which I have reduced as much as I can,
I have the following form for photo_album which uses the nested forms feature of
I have the following form <form name=myForm id=myForm method=post enctype=multipart/form-data action=script.php> and this jQuery
I have a web form which has dynamic table using repeating rows. New rows
I have the following code which I'm using to populate form fields. This 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.