私のアプリケーションでは、たとえば次のようなテーブルがあります。
Question No. Question Answer Marks per Answer Total Marks
1 Here are 2 answers B (text input) 5
D (text input)
2 Here is a single answer True (text input) 5
上記の表には、各回答に属するテキスト入力があります。現在、各質問には独自の合計点数があります。私がやりたいのは、ユーザーがテキスト入力に数字を入力した場合、テキスト入力に入力された数字と「合計マーク」列の下の数字の差を計算する必要があるということです。したがって、以下の例を見ると、次のようになります。
Question No. Question Answer Marks per Answer Total Marks
1 Here are 2 answers B (text input) = 2 2
D (text input) = 1
2 Here is a single answer True (text input) = 5 0
上の表からわかるように、質問1の回答のテキスト入力は合計で3になります。したがって、5(質問1の合計点数から)マイナス3 = 2(合計点数は2になります)
質問2の場合、質問2の回答のテキスト入力は5に等しいため、5(質問2の合計点数から)から5 = 0(合計点数は0になります)を引いたものになります。
私の質問:
- これらの計算を実行するために使用する最良の方法はどのように、そして何ですか?
2.質問に回答が1つしかない場合(上記の例の質問2には回答が1つしかない場合など)、テキスト入力を読み取り専用にし、テキスト入力に同じ番号を表示する必要があります。とにかく同じマークと等しくなければならないので、合計マークは次のようになります。
Question No. Question Answer Marks per Answer Total Marks
2 Here is a single answer True (text input(readonly)) = 5 0
これがjsfiddleデモなので、HTMLコードがどのように見えるかがわかります。jsffidleで行ったことは、テキストボックスに値を挿入したことですが、合計の差を計算すると、実際には両方が「0」になるはずなのに、質問の「合計マーク」を「5」のままにしました。テキスト入力に入力されたマークと数字。また、質問2のテキスト入力は読み取り専用です。これは、この質問に対する単一の回答であるためです。
以下は、jsfiddleにあるhtmlコードです。
<table border='1' id='markstbl'>
<tr>
<th class='questionth'>Question No.</th>
<th class='questionth'>Question</th>
<th class='answerth'>Answer</th>
<th class='answermarksth'>Marks per Answer</th>
<th class='noofmarksth'>Total Marks</th>
</tr>
<tr class="questiontd">
<td class="questionnumtd" rowspan="2">1</td>
<td class="questioncontenttd" rowspan="2">Here are 2 Answers Question</td>
<td class="answertd">B</td>
<td class="answermarkstd"><input class="individualMarks" name="answerMarks[]" id="individualtext" type="text" value="3" /></td>
<td class="noofmarkstd" rowspan="2">5</td>
</tr>
<tr class="questiontd">
<td class="answertd">D</td>
<td class="answermarkstd"><input class="individualMarks" name="answerMarks[]" id="individualtext" type="text" value="2" /></td>
</tr>
<tr class="questiontd">
<td class="questionnumtd" rowspan="2">2</td>
<td class="questioncontenttd" rowspan="2">Here is single Answer Question</td>
<td class="answertd">True</td>
<td class="answermarkstd"><input class="individualMarks" name="answerMarks[]" id="individualtext" type="text" value="5" readonly="readonly"/></td>
<td class="noofmarkstd" rowspan="2">5</td>
</tr>
</table>
たくさんの質問と答えがあり得るとだけ言っておきますが、この例だけに当てはまる答えを提供するだけではありません。質問に多数の回答がある場合は、機能する必要があります。