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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:15:31+00:00 2026-06-11T12:15:31+00:00

I have a radio button like below Apple <input type=radio id=one name=apple data-price=10 value=light/>

  • 0

I have a radio button like below

Apple
<input type="radio" id="one" name="apple" data-price="10" value="light"/> Light
<input type="radio" id="two" name="apple" data-price="20" value="dark" /> Dark
<input type="text" id="appleqty" name="appleqty" value="" />

Mango
<input type="radio" id="three" name="Mango" data-price="30" value="light"/> Light
<input type="radio" id="one" name="Mango" data-price="40" value="dark" /> Dark
<input type="text" id="Mangoqty" name="Mangoqty" value="" />

Pine Apple
<input type="radio" id="four" name="Pineapple" data-price="50" value="light"/> Light
<input type="radio" id="five" name="Pineapple" data-price="60" value="dark" /> Dark
<input type="text" id="Pineappleqty" name="Pineappleqty" value="" />

Grape
<input type="radio" id="six" name="Grape" data-price="70" value="light"/> Light
<input type="radio" id="seven" name="Grape" data-price="80" value="dark" /> Dark
<input type="text" id="Pineappleqty" name="Pineappleqty" value="" />

I this i need to create a array like below

   array
      0 => 
        array
          'apple' => string 'light' (length=10)
          'price' => string '50' (length=1)
      1 => 
        array
          'Pineapple' => string 'dark' (length=10)
          'price' => string '60' (length=1)

A Kind Note : the array key should be the radio button name, the price should be taken from data-price in radio button and i need to serilize this array
This should be done using javascript.

  • 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-11T12:15:32+00:00Added an answer on June 11, 2026 at 12:15 pm

    You’ll need to iterate the <input>s. In order to do so:

    1. If you know beforehand the element names you’ll be looking for (i.e. apple, Mango, and so on), you can do document.getElementsByName on each of those names, as explained in In JavaScript, how can I get all radio buttons in the page with a given name?.

    2. If you don’t know them (they are dynamic), just wrap them in a <div> with a given id and iterate its children, as in how to loop through some specific child nodes.

    While iterating the radios of a given name, inspect the checked property of each in order to know which of them is selected, as in How can i check if a radio button is selected in javascript?.

    You’ll want to build an associative array with keys the following key-value pairs, as in Dynamically creating keys in javascript associative array:

    1. <input>‘s name and value attributes.
    2. literal price and data-price attribute. You’ll need to use getAttribute('data-price') to get the data-price attribute’s value.

    Example:

    function createArray() {
    
        var myArr = new Array();
        myArr[0] = createSubArray('apple');
        myArr[1] = createSubArray('Mango');
        myArr[2] = createSubArray('Pineapple');
        myArr[3] = createSubArray('Grape');
        return myArr;
    }
    
    
    function createSubArray(name) {
        var arr = new Array();
        elems = document.getElementsByName(name);
        for (var i = 0; i < elems.length; i++) {
            if (elems[i].checked) {
                arr[name] = elems[i].value;
                arr['price'] = elems[i].getAttribute('data-price');
            }
        }
        return arr;
    }​
    

    You can see this example working in this JSFiddle.

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

Sidebar

Related Questions

I have radiobutton s like below: Apple <input type=radio id=one name=apple data-price=10 value=light/> Light
i have set of radio buttons like below, <input type=radio NAME=pizzasize value=1/>100&#37; of the
How do i have the radio button show one below the other like this?
I have the following HTML <form id=create_form name=create_form action= method=post> <input name=type id=type value=individuel
I have 3 radio buttons in my web page, like below: <label for=theme-grey> <input
I have 2 radio button with 2 group. The structure is like this Main
In main.xml I would like to have a spinner1 with two radio buttons and
<input type=radio id=Check name=color> <label for=Check >Check it</label> if i wanted to call the
I have a radio group with two radiobuttons. each button has a custom selector.
I have a PHP form that presents the user with two radio button options

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.