NeverPhased
NeverPhased

Reputation: 1566

HTML: More than one variable passed through a single radio input?

I have a website that asks numerous users to fill out a form. There are many sections in the form and each section has some number of radio button inputs. For example below are two sections on the website, the first having 3 inputs and the second having 2 (total of 5 different inputs):

enter image description here

There are many more sections to the form, which gives a combined total of 50 different inputs.

The code for the above example for the Marketing Research Team is as follows:

<input type="radio" name="marketT" value="1" checked="checked"/>
<b>Infinity Market Research Company (IMRC)</b> - &euro;10,000/quarter, +/- 5% accuracy<br/>

<input type="radio" name="marketT" value="2"/>
<b>New Age Marketing Agency (NAMA)</b> - &euro;7,000/quarter, +/- 15% accuracy<br/>

<input type="radio" name="marketT" value="3"/>
<b>Byrne Marketing Consultancy (BMC)</b> - &euro;2,000/quarter, +/- 25% accuracy<br/>

I wish to store various bits of information about each users selection although currently I am only storing a decisionValue of either 1,2 or 3, that continues to 50 for all the other inputs based on the above html.

However I am wondering is it possible to pass more than one value for each radio input. Eg Pass a value of 1, the name of the radio input and the onscreen value

For example if the user selected radio button one for the Marktet Research Team, A value of "1", the text "IMRC", the price "10,000" and the accuracy "5" are all inputted to the system is this possible?

Upvotes: 2

Views: 1748

Answers (2)

Quentin
Quentin

Reputation: 944075

No, it isn't possible, at least not directly.

Things you can do:

  • Make the value an identifier that you map onto something (e.g. a database lookup) on the server
  • Make the value a data structure (e.g. pipe separated, comma separated, or JSON) and parse it on the server
  • Generate hidden inputs using JavaScript

The JavaScript option is the least robust and I don't recommend it.

Upvotes: 2

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114417

You can embed multiple data values using delimiters:

<input type="radio" name="marketT" value="1_50" checked="checked"/>

Then you parse the value on the server to get the embedded data.

Alternately, you can hook up JavaScript events to populate hidden fields. How you do it is up to you.

Upvotes: 1

Related Questions