Here, I am using session to store multiple textbox value.
But when I am going to fetch from session, I am getting the same value for all textbox which is in session.
My code:
if ($order_list) {
$i = $start +1;
foreach ($order_list as $row)
{
?>
<input type="text" name="<?php echo $row['id']; ?>" class="txt" autocomplete="off" id="txtid_<?php echo $row['id']; ?>" value="<?php if(isset($_SESSION['txtval'])) { echo $_SESSION['txtval'];} ?>">
<?php } ?>
In javascript:
$(document).on('blur','.txt',function(){
var myVar = $(this).val();
//alert(myVar);
$.ajax({
type: "GET",
url: "view_orders_checked_array.php",
data: {account: myVar, task: 'alltxt'},
async: false
});
});
In view_orders_checked_array.php :
$task = $_GET['task'];
if($task == "alltxt")
{
$_SESSION['txtval'] = $account;
}
Here, I am not getting the value of particular textbox. I am getting the value which I have last inserted.
Where I am going wrong?
Check below working code, if you just pass the id with your txtval and create session for each id key and value . Now when you print session array you will get all key values in session array. Please ask if difficult to understand.
Javascript
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<?php
session_start();
$_SESSION['txtval'] = '';
$order_list[0] = array('id'=>'1');
$order_list[1] = array('id'=>'2');
$order_list[2] = array('id'=>'3');
$order_list[3] = array('id'=>'4');
$start = '';
if ($order_list) {
$i = $start + 1;
foreach ($order_list as $row) {
?>
<input type="text" name="<?php echo $row['id']; ?>" class="txt" autocomplete="off"
id="txtid_<?php echo $row['id']; ?>" value="<?php if (isset($_SESSION['txtval'])) {
echo $_SESSION['txtval'];
} ?>">
<?php }
}?>
<script type="text/javascript">
$(document).on('blur','.txt',function(){
var myVar = $(this).val();
var myVarid = this.id;
$.ajax({
type: "GET",
url: "view_orders_checked_array.php",
data: {account: myVar, task: 'alltxt', id: myVarid },
async: false,
success:function(data){
console.log(data);
}
});
});
</script>
PHP file view_orders_checked_array.php
<?php
session_start();
$task = $_GET['task'];
if ($task == "alltxt") {
$_SESSION['txtval'][$_REQUEST['id']] = $_REQUEST['account'];
}
echo '<pre>';print_r($_SESSION['txtval'] );echo '</pre>';
die('Call');
you have to maintain array in session also so that you can do with the help of ids
var id=your loop id;
data: {account: myVar, task: 'alltxt',id:id },
and in your view_orders_checked_array page
$task = $_GET['task'];
$id=$_GET['id'];
if($task == "alltxt")
{
$_SESSION['txtval'][$id] = $account;
}
and in your code
<input type="text" name="<?php echo $row['id']; ?>" class="txt" autocomplete="off" id="txtid_<?php echo $row['id']; ?>" value="<?php if(isset($_SESSION['txtval'])) { echo $_SESSION['txtval'][$row['id']];} ?>">
i suggest you to use POST method for passing values
Problem is that you are putting the same value in all text fields
$_SESSION['txtval']
in your loop is always the same.
Edit
And also I think you getting same last inserted value because instead to store all text fields in array $_SESSION['txtval']['another_id_key'] you storing it in $_SESSION['txtval'] which is only one value
Related
I want to get the value of the id in the checkbox. but the variable in id always give the 1st value. how can send php array to jquery array. thanks
require "connection.php";
$sql = mysqli_query($con,"SELECT * FROM position ORDER BY position_align + 0 ASC");
$switch = array();
$pid = array();
while($row = mysqli_fetch_assoc($sql)){
$pcode = $row['position_code'];
$pdesc = $row['position_desc'];
$status = $row['status'];
?>
<tr>
<td><?php echo $pcode; ?></td>
<td><?php echo $pdesc; ?></td>
<td>
<div class="custom-control custom-switch">
<?php
if($status == 'active'){
?>
<div class="onoffswitch4">
<input type="checkbox" name="onoffswitch4" class="onoffswitch4-checkbox switch" onclick="change(this.value)" id="myonoffswitch" checked value="<?php echo $pcode; ?>">
<label class="onoffswitch4-label" for="pid[]">
<span class="onoffswitch4-inner"></span>
<span class="onoffswitch4-switch"></span>
</label>
</div>
<?php
}else{
?>
<div class="onoffswitch4">
<input type="checkbox" name="onoffswitch4" class="onoffswitch4-checkbox switch" onclick="change(this.value)" id="aaa[]" value="<?php echo $pcode; ?>">
<label class="onoffswitch4-label" for="myonoffswitch">
<span class="onoffswitch4-inner"></span>
<span class="onoffswitch4-switch"></span>
</label>
</div>
<?php
}
?>
$('.switch').on('change', function() {
if(this.checked) {
var id = this.value;
$.ajax({
url: "admin_change_status.php",
data: {
id:id
},
type: "POST",
success: function(result){
}
});
}else{
var id2 = this.value;
$.ajax({
url: "admin_change_status.php",
data: {
id2:id2
},
type: "POST",
success: function(result){
}
});
}
});
i expect to get the value of id in checkbox to jquery.
If you want to get all values, you can only get it by classname not by id. You have to loop though all classes names and get each one of them, you can do this by each function. Each function loop though all the elements.
$('.onoffswitch4-checkbox').each(function(i){
var statsValue = $(this).val();
console.log(statsValue);
});
I'm trying to implement live-table edit, but I'm having some trouble with my select options. The input type="text" is fully functional though.
Ever since I tried to add select, it seemed to brake my entire lay-out. First there were multiple rows and columns displayed on the page. But now there's only one and the columns show up empty after the one that contains select.
And the second problem is that ajax doesn't post the table edit since I added select to the mark-up. I'm thinking that this is because the mark-up breaks, but I'm not sure.
If anybody knows what to do, I'd appreciate it.
Markup
<?php
$query = ("select * from projectlist");
$resultaat = mysql_query($query) or die (mysql_error());
while($row = mysql_fetch_array($resultaat, MYSQL_ASSOC)){
$id = $row['projectid'];
?>
<tr class="predit">
<form action="" method="post">
//Working input
<td>
<span id="klant_<?php echo $id; ?>" class="text"><?php echo $row["Klant"]; ?></span>
<input type="text" class="ip" id="klant_ip_<?php echo $id; ?>" value="<?php echo $row["Klant"]; ?>">
</td>
//Same approach, but with select instead of input
<td>
<span id="project_<?php echo $id; ?>" class="text"><?php echo $row["Project"]; ?></span>
<select id="project_ip_<?php echo $id; ?>" class="ip">
<?php
//Fetch select options from another table
$query = ("select * from projecten");
$resultaat = mysql_query($query) or die (mysql_error());
while($row = mysql_fetch_array($resultaat, MYSQL_ASSOC)){
$listid = $row["projectcode"];
$projectnaam = $row["projectnaam"];
?>
<option value="<?php echo $projectnaam; ?>" id="<?php echo $listid; ?>"><?php echo $projectnaam; ?></option>
<?php
}
?>
</select>
</td>
</tr>
</form>
<?php
}
?>
JQuery Ajax
$(document).ready(function(){
//Projeclist
$(".predit").click(function(){
var ID=$(this).attr('id');
$("#klant_"+ID).hide();
$("#project_"+ID).hide();
$("#klant_ip_"+ID).show();
$("#project_ip_"+ID).show();
}).change(function(){
var ID=$(this).attr('id');
var klant=$("#klant_ip_"+ID).val();
var project=$("#project_ip_"+ID).val();
var dataString = 'id='+ ID
+'&Klant='+klant
+'&Project='+project;
//alert(dataString);
var project_txt = $("#project_ip_"+ID+" option:selected").text();
$.ajax({
type: "POST",
url: "post_table.php",
data: dataString,
cache: false,
success: function(html){
$("#project_"+ID).html(project_txt);
$("#klant_"+ID).html(klant);
},
error: function (request, error) {
console.log(arguments);
alert(" Can't do because: " + error);
},
});
});
$(".ip").mouseup(function() {
return false
});
$(document).mouseup(function(){
$(".ip").hide();
$(".text").show();
});
});
post_table.php
<?php
include('config.php');
$klant = $_POST['Klant'];
$project = $_POST['Project'];
$id = $_POST['id'];
$query = "update projectlist
set Klant='$klant',
Project='$project'
where projectid='$id'";
mysql_query($query, $con);
?>
I have a dynamically generated select where customer can choose supplier ($sid) for product ($pid):
<select name="<?php echo $pid; ?>" onchange="func(this.value)">
<?php foreach...{ ?>
<option name="<?php echo $pid; ?>" value="<?php echo $sid; ?>">
<?php echo $value; ?>
</option>
<?php } ?>
</select>
And ajax call which has to assign the chosen value to the product:
<script>
function func(selectedValue){
var pid = $('name').val();
$.ajax({
url: 'update.php',
type: 'POST',
data: {sid : selectedValue, pid : pid},
success: function() {
alert("Ok");
location.reload();
}
});
}
</script>
And update.php
<?php
$pid = $_REQUEST['pid'];
$val = $_REQUEST['sid'];
$sid = json_encode($val);
$query = "UPDATE `orders` SET sid = '$sid' WHERE pid = '$pid'";
try {
$DBH = new PDO("mysql:host=$host;dbname=$db;charset=utf8", $user, $pass);
$STH=$DBH->prepare($query);
$STH->execute();
}
catch(PDOException $e) {
echo $e->getMessage();
}
$DBH=null;
?>
But the information does not update. Where is my mistake?
var pid = $('name').val(); with var pid = selectedValue;
Try this
<?php
$pid = $_REQUEST['pid'];
//$val = $_REQUEST['sid']; // you may write wrong here
//$sid = json_encode($val);
$sid= $_REQUEST['sid'];
$query = "UPDATE `orders` SET sid = '$sid' WHERE pid = '$pid'";
try {
$DBH = new PDO("mysql:host=$host;dbname=$db;charset=utf8", $user, $pass);
$STH=$DBH->prepare($query);
$STH->execute();
}
catch(PDOException $e) {
echo $e->getMessage();
}
$DBH=null;
?>
javascript
<script>
function func(selectedValue){
var pid = $('#product option:selected').attr('name');
$.ajax({
url: 'update.php',
type: 'POST',
data: {sid : selectedValue, pid : pid},
success: function() {
alert("Ok");
location.reload();
}
});
}
</script>
Html:
<select id="product" name="<?php echo $pid; ?>" onchange="func(this.value)">
<?php foreach...{ ?>
<option name="<?php echo $pid; ?>" value="<?php echo $sid; ?>">
<?php echo $value; ?>
</option>
<?php } ?>
</select>
You can replace :
var pid = $('name').val();
with this:
var pid = $(this).attr('name');
The above code will fetch the value of 'name'
The below code will fetch sid
$(this).val();
The problem is you don't get the correct pid because of this wrong jquery selector
$('name').val()
You need to add id attribute to <select> tag, let's say it's product
<select id="product" name="<?php echo $pid; ?>" onchange="func(this.value)">
<?php foreach...{ ?>
<option name="<?php echo $pid; ?>" value="<?php echo $sid; ?>">
<?php echo $value; ?>
</option>
<?php } ?>
</select>
Since $pid is always the same, you can get it by using this selector
$('#product').attr('name')
and set pid to the above as follows
<script>
function func(selectedValue){
var pid = $('#product').attr('name');
$.ajax({
url: 'update.php',
type: 'POST',
data: {sid : selectedValue, pid : pid},
success: function() {
alert("Ok");
location.reload();
}
});
}
</script>
You're missing the important part putting a name to the select not the value.
Instead use id to call your function in your script.
<select name="supplier" id="getValue">
<?php foreach...{ ?>
<option value="<?php echo $sid; ?>">
<?php echo $value; ?>
</option>
<?php } ?>
</select>
On your javascript put this code:
note that the line var formVals = $('form').serialize(); will get all the inputs that your form will pass.
$('#getValue').on('change', function() {
var formVals = $('form').serialize();
$.ajax({
url: "update.php",
type: 'POST',
async : false,
data: formVals,
success: function(data) {
alert("Ok");
location.reload();
}
});
});
and lastly change $_REQUEST to $_POST['supplier'];
Change your HTML like this: (change to onchange="func(this)")
<select name="<?php echo $pid; ?>" onchange="func(this)">
<?php foreach...{ ?>
<option name="<?php echo $pid; ?>" value="<?php echo $sid; ?>">
<?php echo $value; ?>
</option>
<?php } ?>
</select>
And in the code you call ajax:
<script>
function func(element){
var selectedValue = $(element).val();
var pid = $(element).attr('name');
$.ajax({
url: 'update.php',
type: 'POST',
data: {sid : selectedValue, pid : pid},
success: function() {
alert("Ok");
location.reload();
}
});
}
</script>
And in the update.php file:
<?php
$pid = $_POST['pid'];
$val = $_POST['sid'];
$sid = json_encode($val);//I don't know why you have this line, this line should be removed
$query = "UPDATE `orders` SET sid = '$sid' WHERE pid = '$pid'";
try {
$DBH = new PDO("mysql:host=$host;dbname=$db;charset=utf8", $user, $pass);
$STH=$DBH->prepare($query);
$STH->execute();
}
catch(PDOException $e) {
echo $e->getMessage();
}
$DBH=null;
?>
My goal is to submit a set of variables to my AJAX function from with in a while loop in php. This is my first shot at using AJAX, so please excuse if it is messy, and not close to correct. I appreciate any assistance.
PHP FORM:
x=0;
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
$id = $row['col1'];
$ad = $row['col2'];
cho '<form id="msu_form">';
echo "<tr><td>{$ad}</td>";
echo "<td>";
$query2 = "SELECT col1,col2 FROM table WHERE notes = 'x'";
$result2 = mysql_query($query2);
$count2 = mysql_num_rows($result2);
if($count2 > 0)
{
echo '<select class="Primary" name="primary" onchange=doAjaxPost()>';
while($row2 = mysql_fetch_array($result2))
{
echo "<option value=".$row2['col1'].">".$row2['col2']."</option>";
}
echo "</select>";
}else
{
echo "Blah";
}
echo "</td>";
echo "<td>";
$query3 = "SELECT col1,col2 FROM table2 WHERE notes = 'y'";
$result3 = mysql_query($query3);
$count3 = mysql_num_rows($result3);
if($count3 > 0)
{
echo '<select class="Secondary" name="secondary">';
while($row3 = mysql_fetch_array($result3))
{
echo "<option value=".$row3['col1'].">".$row3['col2']."</option>";
}
echo "</select>";
}else
{
echo "Bah";
}
echo "</td>";
echo '<input type="hidden" class="ID" name="ID" value="'.$id.'"/>';
echo '<input type="hidden" class="desc" name="desc" value="'.$ad.'"/>';
//echo '<td>'."<input type='submit' name='btnupdate' value='UPDATE' /></td>";
echo '</form>';
$x = $x+1;
}
So what happens is every time I change any of the "primary" select boxes on the screen, I get the value of the variables on the first line only. I want to receive the values of the form from the select box. I have tested it via a button, that submits the form it is commented out, but that button submits all the correct information to the page, but I don't want to submit the data every time. Is there a way to accomplish my goal?
Thanks - below the ajax if it helps with an answer.
<script>
function doAjaxPost() {
// get the form values
var primary = $(this).val();
var secondary = $(this).parent().next().child('.Secondary').val();
var hidden = $(this).parent().nextAll('.ID').val();
//var desc = $(this).parent().nextAll('#desc').val();
$.ajax({
type: "POST",
url: "functions/database_write.php",
data: $('#msu_form').serialize(),
//data: "Primary="+primary+"&Hidden="+hidden+"&Secondary="+secondary,
success: function(resp){
//we have the response
alert("'" + resp + "'");
},
error: function(e){
alert('Error: ' + e);
}
});
}
</script>
First, in your php code change the following 4 lines (using id)
echo "<select id=Primary name=primary onchange=doAjaxPost()>";
echo "<select id=Secondary name=secondary>";
echo '<input type="hidden" id="ID" name="ID" value="'.$id.'"/>';
echo '<input type="hidden" id="desc" name="desc" value="'.$ad.'"/>';
to (using class) edited
echo '<select class="Primary" name="primary" onchange="doAjaxPost(this)">'; //added (this)
echo '<select class="Secondary" name="secondary">';
echo '<input type="hidden" class="ID" name="ID" value="'.$id.'"/>';
echo '<input type="hidden" class="desc" name="desc" value="'.$ad.'"/>';
Then, in your javascript code, change
function doAjaxPost() {
var primary = $('#Primary').val();
var secondary = $('#Secondary').val();
var hidden = $('#ID').val();
var desc = $('#desc').val();
to edited
function doAjaxPost(sel) { // added (sel)
var primary = $(sel).val(); //changed to $(sel)
var secondary = $(sel).parent().next().children('.Secondary').val(); //changed to $(sel) and changed to children()
var hidden = $(sel).parent().nextAll('.ID').val(); //changed to $(sel) and changed to nextAll()
var desc = $(sel).parent().nextAll('#desc').val(); //changed to $(sel) and changed to nextAll()
If everything works fine when submitting normally, then probably you are generating the ajax data wrong, instead give your form an id:
echo '<form id="myform">';
Then serialize the form to get the correct data:
function doAjaxPost() {
$.ajax({
type: "POST",
url: "functions/data.php",
data: $('#myform').serialize(),
success: function(resp){
//we have the response
alert("'" + resp + "'");
},
error: function(e){
alert('Error: ' + e);
}
});
}
EDIT Ok you edit has cleared things up a bit, I didn't notice you have multiple forms.
Using the same doAjaxPost function as above, change the data property to:
data: $(this).parents('form').serialize();
I have a quiz website. I want to redesign my question form to submit the answer given by the user through AJAX, verify the answer on the server and display the result along with the next answer to the user.
Please guide me how to do this. The codes I am already using are:
<?php
$a = $_REQUEST['ad'];
include("connection.php");
if (isset($_REQUEST['ad']))
{
if ($_REQUEST['ad'] == $a)
{
$q1 = "select * from question WHERE q_id= '$a' AND cat_id='General Knowledge'";
$rw = mysql_query($q1);
if ($row = mysql_fetch_assoc($rw))
{
if ($a % 10 == 0) {
$qno = 10;
} else {
$qno = substr($a, -1, 1);
}
?>
<b><?php echo "Q" . $qno . ". ";
echo $row['q_desc']; ?></b><br/><br/>
<div class="quizimage">
<img src="images/<?php echo $a; ?>.jpg" alt="General Knowledge Quiz"/>
</div>
<font class="common">
<table align="center">
<form action="general-knowledge.php?ad=<?php echo $a; ?>" method="post">
<tr align="center">
<input type="radio" name="ans"
value="<?php echo $row['ans1']; ?>" <?php echo($_POST['ans'] == $row['ans1'] ? 'checked' : '') ?>/>
<?php echo $row['ans1']; ?>
<br/>
<input type="radio" name="ans"
value="<?php echo $row['ans2']; ?>" <?php echo($_POST['ans'] == $row['ans2'] ? 'checked' : '') ?>/>
<?php echo $row['ans2']; ?><br/>
<input type="radio" name="ans"
value="<?php echo $row['ans3']; ?>" <?php echo($_POST['ans'] == $row['ans3'] ? 'checked' : '') ?>/>
<?php echo $row['ans3']; ?><br/>
<input type="radio" name="ans"
value="<?php echo $row['ans4']; ?>" <?php echo($_POST['ans'] == $row['ans4'] ? 'checked' : '') ?>/>
<?php echo $row['ans4']; ?><br/>
</font>
<tr>
<td><input type=submit name=sub value=Submit_Answer></td>
</tr></form></table>
<table border="1" align="center">
<div class="adunit3">
<?php
include "adunit3.php";
?>
</div>
<?php
}
$_SESSION['quiz_visited'] = $a;
if (isset($_POST['sub'])) {
$a_value = $a;
$answer = $_POST['ans'];
$q2 = "select * from question where q_id=$a_value";
$r2 = mysql_query($q2);
if ($row = mysql_fetch_array($r2))
$trueans = $row['true_ans'];
if ($answer == $trueans) {
$score = $_SESSION['score'];
$score = ++$score;
$_SESSION['score'] = $score;
?>
<div class="resultdisplay">
Your answer is correct. <h3>General Knowledge Trivia</h3><?php echo $row['trivia']; ?> <br/> <?php
if ($a % 10 == 0) {
$a = ++$a;
?>
<b>Click Here to view your result.</b>
<?php
} else {
$a = ++$a;
?>
<b>Click Here for next question.</b>
<?php
}
?>
</div>
<?php
} else {
?>
<div class="resultdisplay">
Your answer is wrong. The correct answer is <i>'<?php echo $trueans; ?>'</i>.
<h3>General Knowledge Trivia</h3><?php echo $row['trivia']; ?> <br/>
<?php $a = ++$a; ?>
<b>Click Here for next question.</b>
</div>
<?php
}
}
++$a;
$a = ++$a;
}
}
?>
</table>
You can do that with following structure;
First put $ad variable in hidden element in your form;
<input type="hidden" name="ad" value="<?php echo $a?>"/>
And then
$.ajax({
type: "POST",
url: 'general-knowledge.php',
data: $(".common form").serialize(),
success: function(data) {
if (data.result == true) {
alert("It is correct");
window.location = "next_question.html"
} else {
alert("Incorrrect result");
}
}
});
Check form results by using form variables and question id, and return result on server side
Use this javascript (Jquery code to submit you form).
// frm_id is the id of the form
$("#frm_id").submit(function() {
var url = "path/to/your/script.php"; // the script where you handle the form input and save to database.
$.ajax({
type: "POST",
url: url,
data: $("#frm_id").serialize(), //serializes the form's elements.
success: function(data){
alert(data); // show response from the php script.
}
});
return false; // prevent to execute the actual submit of the form.
});
In response (data) you can bring details of next question.
try something like this
$("#form_id").submit(function() {
$.ajax({
type: "POST",
url: this.action,
data: $(this).serialize(), //Serialize a form to a query string.
success: function(response){
alert(response); //response from server.
}
});
return false; // prevent form to submit.
});
Reference
jQuery Ajax() => http://api.jquery.com/jquery.ajax/
Serialize() => http://api.jquery.com/serialize/
jQuery Submit() => http://api.jquery.com/submit/
jQuery post => http://api.jquery.com/jquery.post/
Example
http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
Submitting HTML form using Jquery AJAX
http://hayageek.com/jquery-ajax-form-submit/
http://www.phpeveryday.com/articles/jQuery-AJAX-Form-Submission-P973.html
1- Set form id = general-knowledge-form
2- load jquery lib on your head tag as following
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
3- create new hidden input <input type="hidden" id="q_id" value="<?php echo $a; ?>" />
4- create new php file for ex: ajax.php to verify user answer then return the appropriate html outbut this file contain the following code:
<?php
mysql_connect('localhost', 'root', 'root');
mysql_select_db('test');
$a = filter_var($_POST['q_id'], FILTER_SANITIZE_NUMBER_INT);
$ans = filter_var($_POST['ans'], FILTER_SANITIZE_STRING);
$q1 = "select * from question WHERE q_id=" . $a;
$rw = mysql_query($q1);
$row = mysql_fetch_object($rw);
?>
<?php if ($ans == $row->true_ans): ?>
<div class="resultdisplay">
Your answer is correct. <h3>General Knowledge Trivia</h3><?php echo $row->trivia; ?> <br/> <?php
if ($a % 10 == 0) {
$a = ++$a;
?>
<b>Click Here to view your result.</b>
<?php
} else {
$a = ++$a;
?>
<b>Click Here for next question.</b>
<?php
}
?>
</div>
<?php else: ?>
<div class="resultdisplay">
Your answer is wrong. The correct answer is <i>'<?php echo $row->true_ans; ?>'</i>.
<h3>General Knowledge Trivia</h3><?php echo $row->trivia; ?> <br/>
<?php $a = ++$a; ?>
<b>Click Here for next question.</b>
</div>
<?php endif;
5- add the following script on end of your page before body tag to handle your ajax request to ajax.php, then append appropriate html to your page
<script>
$(document).ready(function() {
$("#general-knowledge-form").submit(function(event) {
var ans = $('input[name=ans]:checked').val();
if (ans !== undefined) {
var q_id = $("#q_id").val();
$.ajax({
type: "POST",
url: "ajax.php",
data: {q_id: q_id, ans: ans}
})
.done(function(html) {
$("#resultdisplay").empty();
$("#resultdisplay").append(html);
});
} else {
alert('Plz select your answer.');
}
event.preventDefault();
});
});
</script>