How to add points that add up and are display in the page for the student to see how the points are growing
up vote
1
down vote
favorite
I am working in a quiz, it has a dropdown with all the posible answer and a query that give one question at the time and contain the right answer, when they are equal I want the quiz to give 3 points. and I want those 3 points to be shown in the top corner of the page and when the student answer the next question and it is correct I want 3 more points to be added and the new total to be shown in the top corner. I was able to get an alert to tell that the answer was correct and to give an alert that I earn 3 points. But what I really want is to see the points been added and display as they grow with each correct answer not alerts although it was a good start because at least now I know that the query and the dropdown are communicating. I also try echo to see if it's display at least the 3 points but I think that echo don't work with JavaScript function. Thanks in advance for your help, have a great day!
<!-- Select page, A dropdown -->
<select id="author">
<option value="">Select Author</option>
<?php
if($rowCount > 0){
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['authors_id'].'">'.$row['authors'].'</option>';
}
}else{
echo '<option value="">Author not available</option>';
}
?>
</select>
<!-- functionpage-->
$(function() {
$('#author').on('change', function(event) {
var opt = this.options[ this.selectedIndex ];
var correct = $(opt).text().match (arr2);
var score = 0;
if (correct){
alert('Good job ' + arr2,);
score++;
alert (score++);
}
else {
echo ('nice try ' + arr2);
}
});
});
</script>
<script>
var arr2=;
arr2.push('<?php
$query = "Select * from Titles"
$res6 = mysqli_query($db,$query) or die(mysqli_error($db));
while($data = mysqli_fetch_array($res6))
{
echo $data['authors'];
}
?>');
</script>
javascript php jquery html mysql
add a comment |
up vote
1
down vote
favorite
I am working in a quiz, it has a dropdown with all the posible answer and a query that give one question at the time and contain the right answer, when they are equal I want the quiz to give 3 points. and I want those 3 points to be shown in the top corner of the page and when the student answer the next question and it is correct I want 3 more points to be added and the new total to be shown in the top corner. I was able to get an alert to tell that the answer was correct and to give an alert that I earn 3 points. But what I really want is to see the points been added and display as they grow with each correct answer not alerts although it was a good start because at least now I know that the query and the dropdown are communicating. I also try echo to see if it's display at least the 3 points but I think that echo don't work with JavaScript function. Thanks in advance for your help, have a great day!
<!-- Select page, A dropdown -->
<select id="author">
<option value="">Select Author</option>
<?php
if($rowCount > 0){
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['authors_id'].'">'.$row['authors'].'</option>';
}
}else{
echo '<option value="">Author not available</option>';
}
?>
</select>
<!-- functionpage-->
$(function() {
$('#author').on('change', function(event) {
var opt = this.options[ this.selectedIndex ];
var correct = $(opt).text().match (arr2);
var score = 0;
if (correct){
alert('Good job ' + arr2,);
score++;
alert (score++);
}
else {
echo ('nice try ' + arr2);
}
});
});
</script>
<script>
var arr2=;
arr2.push('<?php
$query = "Select * from Titles"
$res6 = mysqli_query($db,$query) or die(mysqli_error($db));
while($data = mysqli_fetch_array($res6))
{
echo $data['authors'];
}
?>');
</script>
javascript php jquery html mysql
Hi Sir, it is hard to help you, using you code example. Please create new jsfiddle with dummy/rendered data with your issue and I will help you in few minutes.
– dganenco
Nov 18 at 17:49
I don't see questions in your code, only a select list with authors.correct
is the result of a call tomatch
, but you pass it an array, whilematch
expects a regular expression as argument.
– trincot
Nov 18 at 21:19
Trincot they are not really questions, one query will show the title of the book and with the dropdown you have to select the author. When they match because in the database every record has a title and an author the I want the program to give 2 points and displayed it. Then if the next one is right add 2 mor points etc
– Elvis Cruz
Nov 18 at 21:43
I could put an alert that alert me when is right or wrong but I want points and display them. And they have to add up with every correct answer. The titles are shown one by one using pagination
– Elvis Cruz
Nov 18 at 21:47
The correct and the match are working fine, I just need to see how I can add a variable outside that can sums up the scores points per page (it is a pagination setup with a limit of 1 at the time from MySQL) and display the current total score.
– Elvis Cruz
Nov 19 at 16:42
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am working in a quiz, it has a dropdown with all the posible answer and a query that give one question at the time and contain the right answer, when they are equal I want the quiz to give 3 points. and I want those 3 points to be shown in the top corner of the page and when the student answer the next question and it is correct I want 3 more points to be added and the new total to be shown in the top corner. I was able to get an alert to tell that the answer was correct and to give an alert that I earn 3 points. But what I really want is to see the points been added and display as they grow with each correct answer not alerts although it was a good start because at least now I know that the query and the dropdown are communicating. I also try echo to see if it's display at least the 3 points but I think that echo don't work with JavaScript function. Thanks in advance for your help, have a great day!
<!-- Select page, A dropdown -->
<select id="author">
<option value="">Select Author</option>
<?php
if($rowCount > 0){
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['authors_id'].'">'.$row['authors'].'</option>';
}
}else{
echo '<option value="">Author not available</option>';
}
?>
</select>
<!-- functionpage-->
$(function() {
$('#author').on('change', function(event) {
var opt = this.options[ this.selectedIndex ];
var correct = $(opt).text().match (arr2);
var score = 0;
if (correct){
alert('Good job ' + arr2,);
score++;
alert (score++);
}
else {
echo ('nice try ' + arr2);
}
});
});
</script>
<script>
var arr2=;
arr2.push('<?php
$query = "Select * from Titles"
$res6 = mysqli_query($db,$query) or die(mysqli_error($db));
while($data = mysqli_fetch_array($res6))
{
echo $data['authors'];
}
?>');
</script>
javascript php jquery html mysql
I am working in a quiz, it has a dropdown with all the posible answer and a query that give one question at the time and contain the right answer, when they are equal I want the quiz to give 3 points. and I want those 3 points to be shown in the top corner of the page and when the student answer the next question and it is correct I want 3 more points to be added and the new total to be shown in the top corner. I was able to get an alert to tell that the answer was correct and to give an alert that I earn 3 points. But what I really want is to see the points been added and display as they grow with each correct answer not alerts although it was a good start because at least now I know that the query and the dropdown are communicating. I also try echo to see if it's display at least the 3 points but I think that echo don't work with JavaScript function. Thanks in advance for your help, have a great day!
<!-- Select page, A dropdown -->
<select id="author">
<option value="">Select Author</option>
<?php
if($rowCount > 0){
while($row = $query->fetch_assoc()){
echo '<option value="'.$row['authors_id'].'">'.$row['authors'].'</option>';
}
}else{
echo '<option value="">Author not available</option>';
}
?>
</select>
<!-- functionpage-->
$(function() {
$('#author').on('change', function(event) {
var opt = this.options[ this.selectedIndex ];
var correct = $(opt).text().match (arr2);
var score = 0;
if (correct){
alert('Good job ' + arr2,);
score++;
alert (score++);
}
else {
echo ('nice try ' + arr2);
}
});
});
</script>
<script>
var arr2=;
arr2.push('<?php
$query = "Select * from Titles"
$res6 = mysqli_query($db,$query) or die(mysqli_error($db));
while($data = mysqli_fetch_array($res6))
{
echo $data['authors'];
}
?>');
</script>
javascript php jquery html mysql
javascript php jquery html mysql
edited Nov 19 at 16:36
asked Nov 18 at 13:00
Elvis Cruz
186
186
Hi Sir, it is hard to help you, using you code example. Please create new jsfiddle with dummy/rendered data with your issue and I will help you in few minutes.
– dganenco
Nov 18 at 17:49
I don't see questions in your code, only a select list with authors.correct
is the result of a call tomatch
, but you pass it an array, whilematch
expects a regular expression as argument.
– trincot
Nov 18 at 21:19
Trincot they are not really questions, one query will show the title of the book and with the dropdown you have to select the author. When they match because in the database every record has a title and an author the I want the program to give 2 points and displayed it. Then if the next one is right add 2 mor points etc
– Elvis Cruz
Nov 18 at 21:43
I could put an alert that alert me when is right or wrong but I want points and display them. And they have to add up with every correct answer. The titles are shown one by one using pagination
– Elvis Cruz
Nov 18 at 21:47
The correct and the match are working fine, I just need to see how I can add a variable outside that can sums up the scores points per page (it is a pagination setup with a limit of 1 at the time from MySQL) and display the current total score.
– Elvis Cruz
Nov 19 at 16:42
add a comment |
Hi Sir, it is hard to help you, using you code example. Please create new jsfiddle with dummy/rendered data with your issue and I will help you in few minutes.
– dganenco
Nov 18 at 17:49
I don't see questions in your code, only a select list with authors.correct
is the result of a call tomatch
, but you pass it an array, whilematch
expects a regular expression as argument.
– trincot
Nov 18 at 21:19
Trincot they are not really questions, one query will show the title of the book and with the dropdown you have to select the author. When they match because in the database every record has a title and an author the I want the program to give 2 points and displayed it. Then if the next one is right add 2 mor points etc
– Elvis Cruz
Nov 18 at 21:43
I could put an alert that alert me when is right or wrong but I want points and display them. And they have to add up with every correct answer. The titles are shown one by one using pagination
– Elvis Cruz
Nov 18 at 21:47
The correct and the match are working fine, I just need to see how I can add a variable outside that can sums up the scores points per page (it is a pagination setup with a limit of 1 at the time from MySQL) and display the current total score.
– Elvis Cruz
Nov 19 at 16:42
Hi Sir, it is hard to help you, using you code example. Please create new jsfiddle with dummy/rendered data with your issue and I will help you in few minutes.
– dganenco
Nov 18 at 17:49
Hi Sir, it is hard to help you, using you code example. Please create new jsfiddle with dummy/rendered data with your issue and I will help you in few minutes.
– dganenco
Nov 18 at 17:49
I don't see questions in your code, only a select list with authors.
correct
is the result of a call to match
, but you pass it an array, while match
expects a regular expression as argument.– trincot
Nov 18 at 21:19
I don't see questions in your code, only a select list with authors.
correct
is the result of a call to match
, but you pass it an array, while match
expects a regular expression as argument.– trincot
Nov 18 at 21:19
Trincot they are not really questions, one query will show the title of the book and with the dropdown you have to select the author. When they match because in the database every record has a title and an author the I want the program to give 2 points and displayed it. Then if the next one is right add 2 mor points etc
– Elvis Cruz
Nov 18 at 21:43
Trincot they are not really questions, one query will show the title of the book and with the dropdown you have to select the author. When they match because in the database every record has a title and an author the I want the program to give 2 points and displayed it. Then if the next one is right add 2 mor points etc
– Elvis Cruz
Nov 18 at 21:43
I could put an alert that alert me when is right or wrong but I want points and display them. And they have to add up with every correct answer. The titles are shown one by one using pagination
– Elvis Cruz
Nov 18 at 21:47
I could put an alert that alert me when is right or wrong but I want points and display them. And they have to add up with every correct answer. The titles are shown one by one using pagination
– Elvis Cruz
Nov 18 at 21:47
The correct and the match are working fine, I just need to see how I can add a variable outside that can sums up the scores points per page (it is a pagination setup with a limit of 1 at the time from MySQL) and display the current total score.
– Elvis Cruz
Nov 19 at 16:42
The correct and the match are working fine, I just need to see how I can add a variable outside that can sums up the scores points per page (it is a pagination setup with a limit of 1 at the time from MySQL) and display the current total score.
– Elvis Cruz
Nov 19 at 16:42
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361131%2fhow-to-add-points-that-add-up-and-are-display-in-the-page-for-the-student-to-see%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hi Sir, it is hard to help you, using you code example. Please create new jsfiddle with dummy/rendered data with your issue and I will help you in few minutes.
– dganenco
Nov 18 at 17:49
I don't see questions in your code, only a select list with authors.
correct
is the result of a call tomatch
, but you pass it an array, whilematch
expects a regular expression as argument.– trincot
Nov 18 at 21:19
Trincot they are not really questions, one query will show the title of the book and with the dropdown you have to select the author. When they match because in the database every record has a title and an author the I want the program to give 2 points and displayed it. Then if the next one is right add 2 mor points etc
– Elvis Cruz
Nov 18 at 21:43
I could put an alert that alert me when is right or wrong but I want points and display them. And they have to add up with every correct answer. The titles are shown one by one using pagination
– Elvis Cruz
Nov 18 at 21:47
The correct and the match are working fine, I just need to see how I can add a variable outside that can sums up the scores points per page (it is a pagination setup with a limit of 1 at the time from MySQL) and display the current total score.
– Elvis Cruz
Nov 19 at 16:42