hi.can anyone give some suggestion on this?
I need to do for a system that calculate the marks. At first, I had created the radio buttons and textboxes for user to insert the marks, but it seems not so user friendly. So I decide to change them into automatically calculate the marks which means that when the user select the radio button, the system will automatically calculate and display the marks in the textbox. For example, maximum marks for question 1 is 5 and rating=1,2,3,4,5 (radio button) and user select 1, therefore the textbox will display value 1.But, for example, when the maximum marks for question 1 is 10 and rating=1,2,3,4,5 (radio button) and user select 3, I believe that most of the people will code the system to calculate and display at textbox witht the value 6. But in manual the marks can be 5 or 6. Therefore, is there any appropriate ways to do this?or any kinds of suggestion or comments which is more suitable to solve this problem are appreciated.Thanks in advance.

p/s:the maximum marks are retrieved from database and display using looping.

populate a select box from zero to the maximum value for the question stored in the database
demo thought process, not code
read max_value from database
for $I < max value
echo <option value=$i>$i</option>
$I++

JUST THOUGHT PROCESS NOT EXPANDED TO ANY USEABLE CODE

Thanks for the reply. If I want the user select the radio button and directly calculate for the value and display in textxbox, then how?Furthermore, How can I save the value of radio button and textbox (the value which calculate automatically) in the database? Thanks.

look up the html <select> tag
the name and value are set,automatic once the <select><option> is chosen, there is no need for any crap with buttons and text boxes
there is no need to calculate anything before submission to the database


for each appplicable question select from database question_name max_value
echo '$question_name <select name=$question_name>';for $i < $max_value
echo '<option value=$i> $i </option>';
$i++echo '</select>';not a code sample a logic example

But for example, if the value is more than 30, then the list is too long for user to select. So I guess can use radio button to select and calculate then show at textbox. Is it possible?

look up the html <select> tag
the name and value are set,automatic once the <select><option> is chosen, there is no need for any crap with buttons and text boxes
there is no need to calculate anything before submission to the database


for each appplicable question select from database question_name max_value
echo '$question_name <select name=$question_name>';for $i < $max_value
echo '<option value=$i> $i </option>';
$i++echo '</select>';not a code sample a logic example

all those select 'year of birth' boxes with every date from 1994 back to 1920 ?? sad that nobody can make a selection
its a very intuitive process, very easy for the user

you could use checklists or selects pouplated from the prior select, if you feel user are too stupid to select from a single list in numeric order from

there are a number of scripts that will provide a checklist to pick a range incremented by whatever value 10 20, then repopulate the checklist with the range value onchange

Sorry. I don't really get what you mean by using the checklist?Can you explain in more details?Thanks.

all those select 'year of birth' boxes with every date from 1994 back to 1920 ?? sad that nobody can make a selection
its a very intuitive process, very easy for the user

you could use checklists or selects pouplated from the prior select, if you feel user are too stupid to select from a single list in numeric order from

there are a number of scripts that will provide a checklist to pick a range incremented by whatever value 10 20, then repopulate the checklist with the range value onchange

if for example you have a range from 0-100
the first list of radiobuttons or select options may be

  • 0-10
  • 11-20
  • 21-30
  • 31-40
  • 41-50
  • 51-60
  • 61-70
  • 71-80
  • 81-90
  • 91-100

which if you select a choice, in this case 71-80, becomes

  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80

in the same place as the primary list,

I prefer selects, a personal thing, look at this select in your browser

<select name='question1' style='text-align:right;'>
<optgroup label='0-10'>
<option value='0'> 0</option>
<option value='1'> 1</option>
<option value='2'> 2</option>
<option value='3'> 3</option>
<option value='4'> 4</option>
<option value='5'> 5</option>
<option value='6'> 6</option>
<option value='7'> 7</option>
<option value='8'> 8</option>
<option value='9'> 9</option>
<option value='10'>10</option>
</optgroup><optgroup label='11-20'>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
</optgroup><optgroup label='21-30'>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
</optgroup><optgroup label='31-40'>
<option value='31'>31</option>
<option value='32'>32</option>
<option value='33'>33</option>
<option value='34'>34</option>
<option value='35'>35</option>
<option value='36'>36</option>
<option value='37'>37</option>
<option value='38'>38</option>
<option value='39'>39</option>
<option value='40'>40</option>
</optgroup><optgroup label='41-50'>
<option value='41'>41</option>
<option value='42'>42</option>
<option value='43'>43</option>
<option value='44'>44</option>
<option value='45'>45</option>
<option value='46'>46</option>
<option value='47'>47</option>
<option value='48'>48</option>
<option value='49'>49</option>
<option value='50'>50</option>
</optgroup><optgroup label='51-60'>
<option value='51'>51</option>
<option value='52'>52</option>
<option value='53'>53</option>
<option value='54'>54</option>
<option value='55'>55</option>
<option value='56'>56</option>
<option value='57'>57</option>
<option value='58'>58</option>
<option value='59'>59</option>
<option value='60'>60</option>
</optgroup><optgroup label='61-70'>
<option value='61'>61</option>
<option value='62'>62</option>
<option value='63'>63</option>
<option value='64'>64</option>
<option value='65'>65</option>
<option value='66'>66</option>
<option value='67'>67</option>
<option value='68'>68</option>
<option value='69'>69</option>
<option value='70'>70</option>
</optgroup><optgroup label='71-80'>
<option value='71'>71</option>
<option value='72'>72</option>
<option value='73'>73</option>
<option value='74'>74</option>
<option value='75'>75</option>
<option value='76'>76</option>
<option value='77'>77</option>
<option value='78'>78</option>
<option value='79'>79</option>
<option value='80'>80</option>
</optgroup><optgroup label='81-90'>
<option value='81'>81</option>
<option value='82'>82</option>
<option value='83'>83</option>
<option value='84'>84</option>
<option value='85'>85</option>
<option value='86'>86</option>
<option value='87'>87</option>
<option value='88'>88</option>
<option value='89'>89</option>
<option value='90'>90</option>
</optgroup><optgroup label='91-100'>
<option value='91'>91</option>
<option value='92'>92</option>
<option value='93'>93</option>
<option value='94'>94</option>
<option value='95'>95</option>
<option value='96'>96</option>
<option value='97'>97</option>
<option value='98'>98</option>
<option value='99'>99</option>
<option value='100'>100</option>
</optgroup></select>

the options are labelled internally

Thanks for the reply.
Now I try to loop the data from database to drop down list.
$a=maximum value; for example, $a=5 so the drop down list will list 1,2,3,4,5.
I need to loop some questions and each questions got its own maximum value, anyone know how to loop the drop down list and list out all the value?

parts of the codes.

while($row = mysql_fetch_array($result))
{
 $a="$row[mark]";
echo "<td width='500' align='left'>$row[question]</td>";
echo "<td align='center' width='500'>
 <select name='a$i'>for($i=1;$i<$a;$i++)
{ <option value='$i'>$i</option>}
    </select><br></td>";
}

Thanks.

<?php
/* dbase connect etc 
using $result= 'select from Quiz_settings question MAX_mark'; */
while($row = mysql_fetch_array($result)) {
 $a=$row['MAX_mark'];
echo "<td width='500' align='left'>$row['question']</td><td align='center' width='500'><select name='$row['question']'>";
for($i=1;$i<=$a;$i++) { echo "<option value='$i'>$i</option>";}
echo "</select><br></td>"; } ?>

Thanks for the reply. It really works. Thanks again.
I am really new to javascript and do a lot of findings to solve my problem but some not really work for me.
May I know after I select the marks, then how I can calculate them and show in a textbox? For example, once I select the marks, it will show in the textbox, then when I select the second, the third, and so on, they are going to add one by one and display in the textbox. How I can do for this? Thanks.

<?php
/* dbase connect etc 
using $result= 'select from Quiz_settings question MAX_mark'; */
while($row = mysql_fetch_array($result)) {
 $a=$row['MAX_mark'];
echo "<td width='500' align='left'>$row['question']</td><td align='center' width='500'><select name='$row['question']'>";
for($i=1;$i<=$a;$i++) { echo "<option value='$i'>$i</option>";}
echo "</select><br></td>"; } ?>

Now I do for my original question, which is the radio button. I just want to multiply. For example, if user choose (radio button) 5, then times 2 and do the same for the rest of the question with different number to multiply. And I need to display each of the value in a textbox and total up them again in a textbox. So I just need to loop all the questions and multiply one-by-one?
I had try as below. But why it show in all textbox once a radio button was clicked? Moreover, it didn't calculate the value I expected. For example, for question 1, no matter what radio button (1,2,3,4,5) I clicked, it remains show value 1 in all the textbox. Why? Didn't the .value property will read the value for that radio button (for example, value 1,2,3,4,5) when it was checked and multiply with the number I write? Anyone can help on this? Thanks in advance.

while($row = mysql_fetch_array($result)) 
 {  
 echo "<td width='50' align='center'>$row[no]</td>"; 
 echo "<td width='500' align='left'>$row[question]</td>"; 
 echo "<td align='center' width='50'>$row[max_mark]</td>"; 
 echo "<td align='center' width='500'>
<input type='radio' name='rating[$i]' id='rating$i' value='1' onClick='calcRadio()'/>1 
<input type='radio' name='rating[$i]' id='rating$i' value='2' onClick='calcRadio()'/>2 
<input type='radio' name='rating[$i]' id='rating$i' value='3' onClick='calcRadio()'/>3 
 <input type='radio' name='rating[$i]' id='rating$i' value='4' onClick='calcRadio()'/>4 
<input type='radio' name='rating[$i]' id='rating$i' value='5' onClick='calcRadio()'/>5</td>"; 
echo "<td align='center' width='50'><input name='score[$i]' type='text' id='title'size='5' align='middle'></td>"; 
echo "</tr>"; 
  
$i++; 
  
 }
function calcRadio()
{
    var rating1 = parseInt(document.getElementById("rating[1]").value);
    document.getElementById("score[1]").value = rating1*1;
 
    var rating2 = parseInt(document.getElementById("rating[2]").value);
    document.getElementById("score[2]").value = rating2*5;
 
    var rating3 = parseInt(document.getElementById("rating[3]").value);
    document.getElementById("score[3]").value = rating3*2;
 
//for the rest are same as above except the number to multiply
}

Please could anyone help me with my radio button project, I wanna display 4 radio buttons, and if Im going to click the INSERT/submit button, the value of the radio button that I have selected will display in a textbox! (SAME PAGE) HELP!!! :(

HELP!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.