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

  • Home
  • SEARCH
  • 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 8255231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:27:15+00:00 2026-06-08T01:27:15+00:00

Hi I have a form that data post something weird… HTML: <form> <input type=radio

  • 0

Hi I have a form that data post something weird…

HTML:

<form>
   <input type="radio" name="datatype" value="1"/> <label>Datatype 1</label>
   <input type="radio" name="datatype" value="2"/> <label>Datatype 2</label>
   <button type="submit">Submit</button>
</form>

FORM 1:

$('form').submit(function(){
    var dt = $(this).serializeArray();
    $.ajax({
        url: 'post.php',
        data: dt,
        ..................
    })
})

FORM 2:

  $('form').submit(function(){
    var opt = $(['input[name=datatype]').val();
    var dt = [{name:'dtype',value: opt }];

    $.ajax({
        url: 'post.php',
        data: dt,
        ..................
    })
})

In FORM 1 datatype properly post with the correct value either 1 or 2. In this part I am using serialize array. Now the weird thing is on FORM 2 if you choose datatype 2 it always post the value of 1. I need to use FORM 2 for some reason… Am glad if anyone could help. Thanks

  • 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-08T01:27:17+00:00Added an answer on June 8, 2026 at 1:27 am

    You should try this:

    $('form').submit(function(){
        var opt = $('input[name=datatype]:checked').val();
        var dt = [{name:'dtype',value: opt }];
    
        $.ajax({
            url: 'post.php',
            data: dt,
            ..................
        })
    })
    

    Why your FORM2 code always get 1

    By default it get the value according to the order in DOM. As radio with value="1" comes first so it select the value 1, though you select the radio with value="2".


    Correction to your code

    Your $(['input[name=datatype]').val(); statement is wrong. it should

    $('input[name=datatype]:checked').val(); which will get the value of checked radio button.

    Your selector may also be:

    $(':radio:checked[name=datatype]').val()
    

    Working sample

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

Sidebar

Related Questions

I have a form that looks something like this: <form id=uploadForm name=uploadForm method=post enctype=multipart/form-data>
If I have an HTML form, let’s say... <form id='myform'> <input type='hidden' name='x' value='y'>
I have a form that looks like this: <form action=/assesment/savelist/ method=post> <input type=hidden name=owner
I have a form that I pre-populate with test data though jQuery. $('INPUT[name=subscription.FirstName]').val('Jef'); but
I have a matrix of objects that contains data in this form: name A,2,name
I have a form that reloads the page with the updated data: <form name=form
I have an HTML form that I need to post to the server with
I have a form that looks something like this <form action=# class=ajax_form method=post id=comment_form
I have a form with some fields in it: <form id=unit> <input type=hidden name=item_id
I have some form values that include HTML entities, for example: <option value=Coup&#232;> Coup&#232;

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.