I have a java script code like below explained, I need to sort out my problems.
i have a data base in which i store question in one table and then store their options in another table, i need the id of the correct answer from question option table to store that id in question table as answer
var template = '';
var count = 1;
function addTextField()
{
template += "<input type='text' id='option_"+count+"' name='name1[]'>";
template += "<input type='radio' id='option_"+count+"' name='answer')>";
document.getElementById("content1").innerHTML = template;
count++;
}
function getId()
{
var radios = document.getElementsByName('answer');
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
// do whatever you want with the checked radio
var id=radios[i].id;
document.write(id);
//var name = document.getElementsById('id');
//document.write(name);
// only one radio can be logically checked, don't check the rest
break;
}
}
}
Here is my php code:
foreach ($names as $value)
{
mysqli_query($con,"INSERT INTO question_options (options,question_id)
values('$value','$qid')");
}
how can i get the id of selected radio text fields?
i need to store the text fileds value in one table and then the id of that row in another table.