The html code which the user whill see and add radio buttons and text boxes is:
<TABLE id="dataTable" width="350px" >
<TR>
<TD> <input type="radio" name="choice[]" value="1" /> </TD>
<TD> <INPUT type="text" name="answerTxt[]"/> </TD>
</TR>
</TABLE>
<INPUT type="button" value="Add" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete" onclick="deleteRow('dataTable')" />
The java script which adds do the whole work is:
function addRow(tableID)
{
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++)
{
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
switch(newcell.childNodes[0].type)
{
case "text":
newcell.childNodes[0].value = "";
break;
case "radio":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
and my code trying to get the data to store them into a table in the database :
$answerTxt = UserInput::getPostVar('answerTxt'); //will get the values which were entered into all the textboxes
$choice = UserInput::getPostVar('choice'); //the values of the radio buttons
foreach($choice as $k =>$v)
{
foreach($answerTxt as $key => $value )
{
DBQuestions::insertPossibleAnswer($connection); //executes an sql query DBQuestions::insertMCQAnswer($connection,$answerTxt[$key],$choice[$k]);//executes an sql query
}
}
Lets say that when the radio button is selected in the table should be stored 1 otherwise should be stored 0.
The table in my table should be like this (example):
PK1 , PK2, TextBox , RadioButton
1 1 hello 1
1 2 hi 0
1 3 salute 0
1 4 sagionara 0
and so on.
But with the above code I get:
PK1 , PK2, TextBox , RadioButton
1 1 hello 1
1 2 hi 1
1 3 salute 1
1 4 sagionara 1
I believe this is because I have set a static value for my radio button in my html code.
Any idea on how I can solve this?
Thank you in advance for your help
The problem is that every time that the code is executed in the database
Additional comment
I must have done some wrong move with the mouse cause a phrase was cut. What I was trying to say is that:
The problem is that every time that the code is executed in the database is stored 1 even if the corresponding button is not selected.

New Topic/Question
Reply



MultiQuote




|