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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:46:09+00:00 2026-06-05T21:46:09+00:00

Im having an issue where Im getting an empty value for the value of

  • 0

Im having an issue where Im getting an empty value for the value of a radio when my ajax form is submitted subsequent times.

Sequentially this is what happens:

  1. User selects a radio and submits form
  2. Get the value of the selected radio var enable = $('input[name=enable]:checked').attr('value');
  3. Post the value via AJAX data: { 'enable' : enable, },

That all works fine. However if the user submits the form again the value of the radio is empty, nothing is submitted.

I am using styles and Jquery to hide the ‘standard’ radios and replace them with styled versions. With the style turned off, I can see that the radios are being selected correctly, however no value is submitted.

I can post some more code if need be. Thanks.

<form method="post" id="add-form" class="form" onsubmit="return false;">
<label>Enable Location</label>
<input type="radio" name="location_enable" id="location_enable" value="enable" checked="checked" />
<input type="radio" name="location_enable" id="location_disable" value="disable" />
<button>Submit</button>
</form>

Validate the form

        <script type="text/javascript">
        $().ready(function() {
            $("#add-form").validate({
                rules: {
                    location_enable: { required: true }
                },
                success: function(span) { 
                    span.html(" ").addClass("checked"); 
                },
                submitHandler: function(form) {
                    $('#add-form').submitForm();
                }
            });
        });
        </script>

Post the data

            <script type="text/javascript">
            $(document).ready(function() {
                $.fn.submitForm = function() {
                    var location_enable = $('input[name=location_enable]:checked').attr('value');

                    $.ajax({
                        type: 'POST',
                        data: { 'location_enable' : location_enable },
                        url: 'script.php',
                        dataType: 'json',
                        success: function($data) {
                            var result = $data.result;
                            var msg = $data.msg;

                            if (result == "success") {
                                formMessageDisplay(msg, result);
                                $(':input', '#add-form').each( function() {
                                    // Set the values to empty
                                    $(':input').val('');
                                });
                            }
                            else {
                                formMessageDisplay(msg, result);
                            }
                        },
                        error: function($data) {
                            formMessageDisplay('<?php echo AJAX_ERROR; ?>', result);
                        }
                    })
                }
            });
        </script>

On the first submission if the user selected ‘enable’ AJAX will post ‘enable’ as the value to script.php. Without reloading the page if the user submits the form again AJAX posts an empty value even is the user has selected ‘enable’.

Sorry, havent used jsFiddle before.

Within Firebug this is the output from two submissions without reloading the page.

json_action addEloc
location_address    Test
location_desc   Test
location_enable enable
location_loc    Test
location_map    enable
location_name   Testing radio
location_postcode   Test
location_state  QLD

Note the two ‘enables’ from the radio fields.

Second submission:

json_action addEloc
location_address    Test
location_desc   Test
location_enable 
location_loc    Test
location_map    
location_name   Testing radio
location_postcode   Test
location_state  QLD

There was no value for the two radios on the second submission.

enter image description here

enter image description here

  • 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-05T21:46:11+00:00Added an answer on June 5, 2026 at 9:46 pm

    This issue occurs due to your this script

    if (result == "success") {
                    formMessageDisplay(msg, result);
                    $(':input', '#add-form').each( function() {
                        // Set the values to empty
                         $(':input').val('');
                    });
    }
    

    You are setting ” to the all input type elements

    $(':input').val('');
    

    that’s why radio button values will also be set to ”, and will return blank response as it is returning now until you refresh the page.

    Instead of doing this you can use reset() function to reset form values.

    $('#add-form').reset();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue getting this jQuery.ajax call to work. When the script executes
I am having an issue getting this to work. On our form we validate
I'm having an issue getting a LINQ query to work. I have this XML:
I'm having an issue getting this CSS for a sprite sheet to work on
I'm having an issue getting the correct value from my drop down box. Basically
I am getting into C# and I am having this issue: namespace MyDataLayer {
I'm new to GWT, and having an issue getting the result of an AJAX
I am having an issue getting blast_seconds to show up as the correct value.
I'm having an issue getting surefire to run Junit4 tests. This same issue was
I'm having an issue getting some code to work. Is there a way to

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.