PDA

View Full Version : problem in sencha touch quiz



hemant1
19 Jun 2011, 9:59 PM
Hi,

I m creating a quiz in sencha touch
when i run the application
first question of quiz is displayed on the screen after selecting the checkbox when click on the submit button it shows mw the msg that you are right or wrong but after displaying the message its doesn't move to the second question which i call through questionPanel.setActiveItem(question2,slide) (highlighted in the code)

pls give me suggestion how can i move to the next question





var PageCount = 1;
var question1 = new Ext.form.FormPanel({
items: [{
xtype: 'fieldset',
title: 'What is the correct Answer from the following',
instructions: 'Please Choose the correct Answer.',
Q1a:"Correct Answer1",
defaults: {
// labelAlign: 'right'
labelWidth: '35%'
},

items: [{

xtype: 'checkboxfield',
name: 'q1_answer',
label: 'Que1 Correct Answer 1',
value: 'Q1a'
}, {
xtype: 'checkboxfield',
name: 'q1_answer',
label: 'Que1 Incorrect Answer1',
value: 'Q1b'
}, {
xtype: 'checkboxfield',
name: 'q1_answer',
label: 'Que1 Incorrect Answer2',
value: 'Q1c'
}, {
xtype: 'checkboxfield',
name: 'q1_answer',
label: 'Que1 Correct Answer2',
value: 'Q1d'
}
]
}
]
// alert("In Question 1");
});

var question2 = new Ext.form.FormPanel({
items: [{
xtype: 'fieldset',
title: 'What is the correct Answer from the following',
instructions: 'Please Choose the correct Answer.',
Q2a:"Correct Answer2",
defaults: {
// labelAlign: 'right'
labelWidth: '35%'
},

items: [{

xtype: 'checkboxfield',
name: 'q2_answer',
label: 'Que2 Correct Answer 1',
value: 'Q2a'
/* listeners: {
check: function (button) {
Ext.Msg.alert('Title', 'Option1 is checked.', Ext.emptyFn);
}
}*/
}, {
xtype: 'checkboxfield',
name: 'q2_answer',
label: 'Que2 Incorrect Answer1',
value: 'Q2b'
}, {
xtype: 'checkboxfield',
name: 'q2_answer',
label: 'Que2 Incorrect Answer2',
value: 'Q2c'
}, {
xtype: 'checkboxfield',
name: 'q2_answer',
label: 'Que2 Correct Answer2',
value: 'Q2d'
}
]
}
]
});

var question3 = new Ext.form.FormPanel({
items: [{
xtype: 'fieldset',
title: 'What is the correct Answer from the following',
instructions: 'Please Choose the correct Answer.',
Q3a:"InCorrect Answer1",
defaults: {
// labelAlign: 'right'
labelWidth: '35%'
},

items: [{

xtype: 'checkboxfield',
name: 'q3_answer',
label: 'Que3 Correct Answer 1',
value: 'Q3a'
/* listeners: {
check: function (button) {
Ext.Msg.alert('Title', 'Option1 is checked.', Ext.emptyFn);
}
}*/
}, {
xtype: 'checkboxfield',
name: 'q3_answer',
label: 'Que3 Incorrect Answer1',
value: 'Q3b'
}, {
xtype: 'checkboxfield',
name: 'q3_answer',
label: 'Que3 Incorrect Answer2',
value: 'Q3c'
}, {
xtype: 'checkboxfield',
name: 'q3_answer',
label: 'Que3 Correct Answer2',
value: 'Q3d'
}
]
}
]
});

var question4 = new Ext.form.FormPanel({
items: [{
xtype: 'fieldset',
title: 'What is the correct Answer from the following',
instructions: 'Please Choose the correct Answer.',
Q4a:"Incorrect Answer2",
defaults: {
// labelAlign: 'right'
labelWidth: '35%'
},

items: [{

xtype: 'checkboxfield',
name: 'q4_answer',
label: 'Que4 Correct Answer 1',
value: 'Q4a'
/* listeners: {
check: function (button) {
Ext.Msg.alert('Title', 'Option1 is checked.', Ext.emptyFn);
}
}*/
}, {
xtype: 'checkboxfield',
name: 'q4_answer',
label: 'Que4 Incorrect Answer1',
value: 'Q4b'
}, {
xtype: 'checkboxfield',
name: 'q4_answer',
label: 'Que4 Incorrect Answer2',
value: 'Q4c'
}, {
xtype: 'checkboxfield',
name: 'q4_answer',
label: 'Que4 Correct Answer2',
value: 'Q4d'
}
]
}
]
});
function IncrementPageCount(){
if (PageCount < 12){
PageCount++;
}
}

function DecrementPageCount(){
if (PageCount > 1){
PageCount--;
}
}

var questionToolbar = new Ext.Toolbar({
dock: 'bottom',

layout: {
pack: 'center'
},
defaults: {
iconMask: true
},
items: [{
iconCls: 'arrow_left',
handler: function () {
questionPanel.layout.prev({
type: 'slide',
direction: 'right',
handler: DecrementPageCount()
});
}
}, {
text: 'Submit',
ui: 'confirm',
handler: function () {
if (PageCount == 1) {
var valuesQ1 = question1.getValues(),
answerQ1 = valuesQ1.q1_answer;
if (answerQ1 == "Q1a") {
Ext.Msg.alert("Well Done!", "You selected the right answer.");
questionPanel.setActiveItem(question2, 'slide');
IncrementPageCount();
addPoint();
alert("End of IF");
} else {
Ext.Msg.alert("Incorrect", "You selected the wrong answer.");
questionPanel.setActiveItem(question2, 'slide');
IncrementPageCount();

}
alert("You've got " + totalScore);
} else if (PageCount == 2) {
var valuesQ2 = question2.getValues(),
answerQ2 = valuesQ2.q2_answer;
if (answerQ2 == "Q2a") {
Ext.Msg.alert("Well Done!", "You selected the right answer.");
questionPanel.setActiveItem(question3, 'slide');
IncrementPageCount();
addPoint();
} else {
Ext.Msg.alert("Incorrect", "You selected the wrong answer.");
questionPanel.setActiveItem(question3, 'slide');
IncrementPageCount();
}
alert("You've got " + totalScore);
} else if (PageCount == 3) {
var valuesQ3 = question3.getValues(),
answerQ3 = valuesQ3.q3_answer;
if (answerQ3 == "Q3a") {
Ext.Msg.alert("Well Done!", "You selected the right answer.");
questionPanel.setActiveItem(question4, 'slide');
IncrementPageCount();
addPoint();
} else {
Ext.Msg.alert("Incorrect", "You selected the wrong answer.");
questionPanel.setActiveItem(question4, 'slide');
IncrementPageCount();
}
alert("You've got " + totalScore);
} else if (PageCount == 4) {
var valuesQ4 = question4.getValues(),
answerQ4 = valuesQ4.q4_answer;
if (answerQ4 == "Q4a") {
Ext.Msg.alert("Well Done!", "You selected the right answer.");
// questionPanel.setActiveItem(question5, 'slide');
IncrementPageCount();
addPoint();
} else {
Ext.Msg.alert("Incorrect", "You selected the wrong answer.");
// questionPanel.setActiveItem(question5, 'slide');
IncrementPageCount();
}
alert("You've got " + totalScore);
}
}
}, {
iconCls: 'arrow_right',
handler: function () {
questionPanel.layout.next({
type: 'slide',
direction: 'left',
handler: IncrementPageCount()
});
alert(PageCount);
}
}]

});
var totalScore = 0;

function addPoint(){
totalScore++;
}

demos.Forms = new Ext.Panel({
id: 'questionPanel',
cls: 'card',
iconCls:'more',
title: 'Questionnaire',
layout: 'card',
items: [
question1,
question2,
question3,
question4

],
dockedItems: [
questionToolbar
]
});


thanks,