dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Calculate Checked Radio Button

  1. #1
    Join Date
    Aug 2014
    Posts
    1

    Question Calculate Checked Radio Button

    Hello everyone!

    First, apology for my bad English and i'm newbie in PHP environment

    Ok, my question is, how can i calculate the number of selected radio button in my form? Most of the solution is on how to calculate the value from the checkbox, but in my case, i need to calculate the total number of selected radio button. Here the code for my form:

    HTML Code:
    <form id="form1" name="form1" method="post" action="">
      <table width="1100px" border="1">
        <tr>
          <td>No</td>
          <td>Questions</td>
          <td>A</td>
          <td>B</td>
          <td>C</td>
          <td>D</td>
        </tr>
        <tr><!--Question 1-->
        <td>1.</td>
        <td>Question 1</td>
          <td><label><input type="radio" name="q1" value="0" id="q1" />0</label></td>
          <td><label><input type="radio" name="q1" value="1" id="q1" />1</label></td>
          <td><label><input type="radio" name="q1" value="2" id="q1" />2</label></td>
          <td><label><input type="radio" name="q1" value="3" id="q1" />3</label></td>
        </tr>
    	
    	
        <tr><!--Question 2-->
        <td>2.</td>
        <td>Question 2</td>
          <td><label><input type="radio" name="q2" value="0" id="q2" />0</label></td>
          <td><label><input type="radio" name="q2" value="1" id="q2" />1</label></td>
          <td><label><input type="radio" name="q2" value="2" id="q2" />2</label></td>
          <td><label><input type="radio" name="q2" value="3" id="q2" />3</label></td>
        </tr>
    	
    	<tr><!--Question 3-->
        <td>3.</td>
        <td>Question 3</td>
          <td><label><input type="radio" name="q3" value="0" id="q3" />0</label></td>
          <td><label><input type="radio" name="q3" value="1" id="q3" />1</label></td>
          <td><label><input type="radio" name="q3" value="2" id="q3" />2</label></td>
          <td><label><input type="radio" name="q3" value="3" id="q3" />3</label></td>
        </tr>
    	
    	<tr><!--Question 4-->
        <td>4.</td>
        <td>Question 4</td>
          <td><label><input type="radio" name="q4" value="0" id="q4" />0</label></td>
          <td><label><input type="radio" name="q4" value="1" id="q4" />1</label></td>
          <td><label><input type="radio" name="q4" value="2" id="q4" />2</label></td>
          <td><label><input type="radio" name="q4" value="3" id="q4" />3</label></td>
        </tr>
    	
    	<tr><!--Question 5-->
        <td>5.</td>
        <td>Question 5</td>
          <td><label><input type="radio" name="q5" value="0" id="q5" />0</label></td>
          <td><label><input type="radio" name="q5" value="1" id="q5" />1</label></td>
          <td><label><input type="radio" name="q5" value="2" id="q5" />2</label></td>
          <td><label><input type="radio" name="q5" value="3" id="q5" />3</label></td>
        </tr>
       
      </table>
    <input name="Calculate" type="button" value="Calculate" />
    </form>
    and here the output:
    Capture.JPG

    How do i calculate the total number of selected radio button for column A, column B, column C and column D. If anybody found any tutorial links to share are also most welcome. Thank you very much and really appreciate!

  2. #2
    Join Date
    Mar 2012
    Posts
    1,834
    1. A table is for tabular data, not for arranging buttons in columns and rows.
    2. Your table is incorrect anyway.
    3. NAMEs and IDs have to be unique on a page.
    4. There is no action in the form, nor PHP in the page, so how are you calculating anything???

  3. #3
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    895
    Radio buttons are designed for and usually used to give a user ONE selection out of a set of choices. Therefore for any group of radio buttons there will only be one or none selected. By examining your POST array for the radio button set name you will know if there was one selected or not. If you have multiple groups of radio buttons (for choosing an item from multiple sets of choices then you will analyze each set name in your post array.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles