Reputation: 867
I am working in extjs. i am displaying 10 questions and its related options. On the click of submit button,i want to retreive selected radio buttons value. I am having view form as= QbqnsView.js
Ext.define('Balaee.view.qb.qbqns.QbqnsView',
{
extend:'Ext.view.View',
id:'qbqnsViewId',
alias:'widget.QbqnsView',
//store:'kp.PollStore',
store:'qb.QbqnsStore',
config:
{
tpl:'<tpl for=".">'+
'<div id="main">'+
'</br>'+
// '<b>Question :-</b> {pollQuestion}</br>'+
'<b>Question :-</b> {question}</br>'+
'<tpl for="options">'+ // interrogate the kids property within the data
//'<p>  <input type="radio" name="{optionId}"> {option}</p>'+
'<p>  <input type="radio" name="{parent.questionId}"> {option}</p>'+
//'<p>  <input type="radio" name="{questionId}"> {option}</p>'+
'</tpl></p>'+
'<p>---------------------------------------------------------</p>'+
'</div>'+
'</tpl>',
itemSelector:'div.main',
}
Qbqns.js=
Ext.define('Balaee.view.qb.qbqns.Qbqns',
{
extend:'Ext.form.Panel',
requires:[
'Balaee.view.qb.qbqns.QbqnsView'
],
id:'qbqnsId',
alias:'widget.Qbqns',
title:'Qbqns',
//height:400,
items:[
{
xtype:'QbqnsView',
},
],//end of items square
buttons:[
{
xtype:'button',
fieldLabel:'Vote',
name:'vote',
formBind:true,
text:'submit',
// action:'voteAction',
listeners: {
click: function(btn,e,eOpts) {
var answers =
Ext.core.DomQuery.select("input[type='radio']:checked");
console.log(answers);
}
}
}
]
So on the click of submit button,its giving me value as 'input,input,......' . Its not giving me actual option value. So how to retrive actial value of selected option? Please help me
Upvotes: 0
Views: 3307
Reputation: 2349
Try following code to get selected radio button -
//put value of {parent.questionId} in getElementsByName()
var inputs = document.getElementsByName("");
var radio = "";
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].checked) {
radio = inputs[i].name;
}
}
Upvotes: 1