Reputation: 1384
I've got the following code, which writes radiobuttons through javascript to HTML
document.write('<input type="radio" name="AnswerA" />' + res.rows[jsonCounter][1]);
Say, I want to access this AnswerA field and find out if it's been selected, I can try :
if(document.getElementById('AnswerA').checked) {
}
But this doesn't seem to work - can anyone see what I'm doing wrong?
Upvotes: 0
Views: 82
Reputation: 381
Add id in your DOM element. It will work.
document.write('<input type="radio" id="AnswerA" name="AnswerA" />' + res.rows[jsonCounter][1]);
Upvotes: 1
Reputation: 2155
You need to set an id
on the new DOM element for document.getElementById
to use:
document.write('<input type="radio" name="AnswerA" id="AnswerA" />' + res.rows[jsonCounter][1]);
Upvotes: 3