# Multiple values for radio buttons in HTML form?



## mathlete (Jul 5, 2006)

Hello,

I'm rather new to HTML/PHP, so please be patient with me. I was wondering if it is possible for an input in a HTML form to have multiple values? For example, suppose I have:


<form action="submit.php" method="post" enctype="multipart/form-data" name="postForm">
Chapter 1<br>
<input type="radio" name="pageNum" value="Ch1_P1">Page 1</input><br>
<input type="radio" name="pageNum" value="Ch1_P2">Page 2</input><br>

Chapter 2<br>
<input type="radio" name="pageNum" value="Ch2_P1">Page 1</input><br>

<input type="submit" value="Submit"></input>
</form>


Would it be possible for me to set the value of each radio button to be an array or something? That is, instead of value="Ch1_P1", have something like value=["Ch1","P1"]? I want to do it this way so that in the PHP page, I won't have to worry about parsing the "Ch1_P1" string to find out the chapter and the page. Ideally, if the form can submit an array as a value, then I can just do this in submit.php:


$selected = $_POST['pageNum'];
$chapter = $selected[0];
$page = $selected[1];


I've considered using multiple radio button groups, but that would mean the user would be able to select more than one page from different chapters. I'm not particularly attached to having to do it this way - submitting array values - so any suggestion about other ways of doing this would be very welcome. Mainly, all I want is: 1)To limit the user to selecting only ONE option and 2)For that one option to carry multiple value information (chapter, page, line, etc.) that can be easily separated and identified in PHP. 

Thanks in advance.


----------



## gamerman0203 (Oct 28, 2005)

I'm not big on PHP, but I do know HTML and ASP really well. ASP and PHP aren't too far off in some sense. However, the only way to pass on multiple values it to parse them. You can list multiple values like this -- value="1,2,3,4,etc" -- seperated by commas, but it still needs to be parsed, either be PHP, ASP, JavaScript, etc.


----------



## mathlete (Jul 5, 2006)

Ah...alright. Thanks for clearing up my confusion!


----------

