exam portal questions and answers cache procedure - javascript

I am a learner and trying to develop a webportal for online mocktests.
in this portal, after being redirected to the mocktest page, the exam page look something like... a php page having a
1. timer on top
2. two iframes - one on left and one on right - src is php file
The left iframe would contain all buttons displaying questions number.
Right frame would display the question and answer options as radio buttons.
The problem is with caching the questions. Once I check a radio button of questionx, navigate to some other question and come back to the questionx again, the checked option is not visible.. which is to say that the question is again queried from database and displayed afresh. I want already visited questions, selected answers to be cached.
How should I accomplish this?
the mocktest web page looks like this
code for mocktest web page include the frames like below -
<!-- questions numbers left div -->
<div class="left">
<Iframe id="frame1" name="iframe1" src="Questions/QuantitativeAptitude.php" ></Iframe>
</div> <!--div classs=left -->
<!-- display question right div-->
<div class="right">
<Iframe id="frame2" name="iframe2" src="Questions/displayQuestion.php"></Iframe>
</div> <!--div classs=right -->
QuantitativeAptitude.php contains a form, from which a buttom is created
<form name="frm2" >
<input id="questionButton" type="button" name="questionNum" value="<?php echo $questionNum;?>" onclick="parent.hello(this.form.questionNum.value);">
</form>
javascript function defined in the parent page i.e., mocktest page pass the clicked/selected question number to displayQuestion.php file
in displayQuestion.php file, question is retrieved using _GET, query database, display question and answer options through a form.
<FORM method="POST" >
<INPUT TYPE="RADIO" VALUE="1" NAME="theAnswer" onclick="return displayAnswer(value)">
<span class="answerOptions">1. <?php echo $Option1; ?><BR><BR> </span>
<INPUT TYPE="RADIO" VALUE="2" NAME="theAnswer" onclick="return displayAnswer(value)">
<span class="answerOptions">2. <?php echo $Option2; ?><BR><BR></span>
<INPUT TYPE="RADIO" VALUE="3" NAME="theAnswer" onclick="return displayAnswer(value)">
<span class="answerOptions">3. <?php echo $Option3; ?><BR><BR></span>
<INPUT TYPE="RADIO" VALUE="4" NAME="theAnswer" onclick="return displayAnswer(value)">
<span class="answerOptions">4. <?php echo $Option4; ?><BR><BR></span>
<INPUT TYPE="RADIO" VALUE="5" NAME="theAnswer" onclick="return displayAnswer(value)">
<span class="answerOptions">5. <?php echo $Option5; ?><BR><BR></span>
</FORM>
to capture the checked radio button in order to store in database I tried two methodologies -
1. javascript
2. jquery
method 1: javascript
function displayAnswer(answer){
var optionSelected = answer;
alert (optionSelected);
return true;
}
With this methodology, I could see the alert message stating the selected option only for few questions, not all. Also, using javascript, it will be tedious to pass this "optionSelected " variable to another php file where the database would be updated with user selected answer.
**NOTE:**I placed a breakpoint in the above javascript code, using developer tool(F12). As obvious, code did not break for those questions where the alert message was not seen.
method 2:jquery
here I have downloaded jquery-1.12.4.min.js into my xampp project js folder and included into the php file. After, writing jquery, few of the questions itself stopped displaying.
<script>
$('input:radio').change(function(){
var value = $("form input[type='radio']:checked").val();
alert("Value of Changed Radio is : " +value);
});
</script>
Using this jquery, only question 1, 2, 3, 7 are displayed out of 70(in 5 tabs) questions in mocktest. I do not understand why only these questions are displayed and why remaining questions are not displayed.
database sample data
From the data shown in attached image, question 4, 5, 6, 8 popup alert message when radio button is checked.

Related

Retain value of radio button after validation php

My issue is once user click submit the form should check for all questions that the radio button is checked.
It should show the err message on the questions where the user didn't answer.
But right now the form refreshed everytime after the err message is shown and the
previous checked radio button is lost.I also have javascript timer going on,but
since the page get refreshed ,the timer starts all over again.
Im newbie to php,kindly guide me through this issue.Any help is appreciated.
<?php session_start()?>
<?php
$errorexist=false;
if (isset($_POST["submit"])){
for ($y=0;$y<5;$y++)
{
if(empty($_POST["question".$y])){
$errorexist=true;
${"err".$y}="* Please answer question ".($y+1)."<br>";
}
}
if (errorexist==false){
header ("Location: result.php");
exit;}
} ?>
html part of the code
<li>
<span class="error"><?php echo $err0?></span>
<h3>What is the smallest prime number?</h3>
<input type="radio" name="question0" value="A"<?php echo ($question0=='A')? 'checked':''; ?> />2<br>
<input type="radio" name="question0" value="B"<?php echo ($question0=='B')? 'checked':''; ?> />1<br>
<input type="radio" name="question0" value="C"<?php echo ($question0=='C')? 'checked':''; ?> />3<br>
<input type="radio" name="question0" value="D"<?php echo ($question0=='D')? 'checked':''; ?> />4<br>
</li>
Put a condition, where if any radio button misses it displays the
error message and no need to refresh the page. Inside the PHP code,
Request submit button
Request all the radio button. i.e $question1 = $_REQUEST['question1'];
check if all the values are set and not empty if(isset($question1) && !empty($question1) && $question1 !== '')
do this for all, close this condition with the error message.
This might help.

How to prevent a form from opening action url and only print when submitted?

i am building a form and when i submit it it opens the action url. I want to submit the form on click button which should not open the target url but submit the request. as well as i want to print a message after submit and form should be cleared after submit.
<form id="contact" action="https://control.msg91.com/api/sendhttp.php" method="post">
<h3>Send SMS</h3>
<h4>Build in Process</h4>
<fieldset>
<input name="authkey" type="hidden" value="auth key as required"/>
<input name="mobiles" placeholder="Mobile Number" type="text" tabindex="1" maxlength="10" required >
</fieldset>
<fieldset>
<textarea name="message" placeholder="Type your message here...." tabindex="2" maxlength="320" required></textarea>
</fieldset>
<input name="sender" type="hidden" value="FAKEin" />
<input name="route" type="hidden" value="4" />
<input name="country" type="hidden" value="0" />
<fieldset>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
</fieldset>
</form>
any help how can i do this?
also can i add a hidden text in message tab that should add to the message tab in post/get as + instead of &
eg. actionurl.php?authkey=custommade&mobiles=9999999999&message=orginal+message+hidden+message&sender=FAKEin&route=4&country=0&submit=
You can also check the source code of page https://www.tricksbygoogle.com/sms/sms.php
Basically You can't .
The only solution here I see , is using ajax query and use javascript to clear form.
This example I provide is no redirections at all. What means you page will not be reloaded.
Maybe little jquery will help.
var result_func = function(response){
if(response.allOk){
$this.reset();
}
}
$('#contact').submit(function(e){
e.preventDefault()l
var $this = $(this);
var data = $this.serialize();
$.post($this.attr('action'),data,result_func.bind($this));
});
Header location will work , but user still will be redirected.
Based on your question, and the comments it looks like you're going to have to do a little bit of research. Here are some tips though.
If you would like to include the functions from a page without actually visiting the page, than you can use what is called an include statement. This will keep the browser from visiting that page while still executing it. - http://php.net/manual/en/function.include.php
To display a message you're going to need to hide and show the element with javascript. I would suggest viewing this question - Hide div after a few seconds
Basically on submit, you're going to want to check for the variables from your form. You would run a php if statement.
Then, if those variables exist you are going to want to include your action page.
In the same if statement, you're going to want to echo a <div> with a class that has some javascript attached to it to hide it after a few seconds.
The form will automatically clear on submit.
if($variable != null){
include '/action.php' // --- you can add some GET variables to the end of this if you would like to.
echo '<div id="message">Message sent</div>'
}

Disable submit button after submit and page refresh

What i want is pretty simple, i have a button that submits a value to my database once clicked, what i need is to diable the button parmanently after value has been submited, i have searched and the codes i have seen all enable the button when the page refreshes.. please can someone help me out?
My form and button code as follows:
<form action="<?php echo $editFormAction; ?>" method="POST" name="Status2" id="Status2" onSubmit="return confirm('Are you sure you want to submit?');">
<input name="Confirm2" type="checkbox" id="Confirm2" value="Confirmed" checked="CHECKED" style="display:none;">
<label for="Confirm2"></label>
<input name="UpdateButton3" type="submit" class="art-button" id="UpdateButton3" value="Confirm"/>
<input name="UserIDHiddenField4" type="hidden" id="UserIDHiddenField4" value="<?php echo $row_User['UserID']; ?>">
<input name="Purge2" type="checkbox" id="Purge2" value="You Will Be Rematched Soon!" checked="CHECKED" style="display:none;">
<label for="Purge2"></label>
<input type="hidden" name="MM_update" value="Status2">
</form>
First of all if you submit it, this has nothing to do with javascript. Save this in your database as #georoot says. Then when you submit, save a value in the database. If that value is set, you can disable the button by just HTML:
<input type="submit" <?php if($valueFromDatabase==1){ ?> disabled <?php } ?> >
Best solution could be to set a cookie on client system and/or get user IP and save it into your database, but you should keep in mind, non of them are permanent ! The IP can be changed and the cookie can be removed ! But you can use both cookie and IP check.
Then for each page load, just check if cookie exist (compare the value with ur database value) and/or client IP is already exist in database.
Or if you know who is on the page (if it's a logged user) just add a field in your database and set value = 1 or = 0 and check the field each time it's loaded for same field and for same user.
I wouldn't recommend to use IP check without cookies ! Because it can change frequency !

Beginners help to HTML [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to create a html page that will accept inputs from one webpage then print out the user results on a seperate HTML page. So far I have this. When I go and check my action_page.php file nothing is being written into it. Is there anyway I can have my inputs print directly on a second HTML page and constantly updating? Also is there any way for an outside application to control or change the values that are shown on the second webpage?
So I guess a more clear description of what I am trying to do is on one page its accepts input A,B,C then on another html page that have the previous A,B,C values I would like to update the values with the new user submitted values. The second webpage needs to also be static in the sense that the first html page would be website.com/UserInput and the second html page would be website.com/PrintedUserInput. I hope that helps. Thanks
<html>
<body>
<form action="action_page.php">
Time:
<br>
<input type="number" name="Time" value="">
<br>
Temperature:
<br>
<input type="number" name="Temperature" value="">
<br>
Instant Brew:
<br>
<input type="number" name="InstantBrew" value="">
<br>
<br>
<input type="submit" value="Submit">
</form>
<p>If you click "Submit", the form-data will be sent to a page called "action_page.php".</p>
</body>
</html>
All you have to do, is put the "method" attribute to your form like this:
<form action="action_page.php" method="post">
You absolutely need a server side language then to print them out. Since you use your page with the PHP extension, I'm guessing you're using PHP. So then you can call them that way in your other page:
<html>
<body>
Time: <?= $_POST['Time'] ?>
<br>
Temperature: <?= $_POST['Temperature'] ?>
etc, where the name you put between your POST braces is the "name" attribute of your input. Note that name attribute is case sensitive
Hope it helped !

How do I set a counter to a yes or no radio form, which incriments when submitted?

I am new with javascript and have a hard time grasping the concept. I want to add a yes or no form, which submits and adds up when submitted.
Here is the form html:
<form id="selection" name="selection" method="post">
<input type="radio" name="choice" value="yes">Yes<br>
<input type="radio" name="choice" value="no">No<br />
<input type="reset" name="submit" value="Submit" />
</form>
<div id="results">
Voters who said yes are: <label id="yes">0</label><br />
Voters who said no are: <label id="no">0</label><br />
</div>
If you want to keep track of the total yes/no votes submitted across many different computers, then you will need to keep those totals on the server that you are posting the votes to.
When a vote is posted, you can increment the vote count on the server (probably stored in a database on the server).
If you want the total votes so far displayed in your web page, then you would have to either put that data in the web page on your server when the web page is generated or you would have to fetch the count with an ajax call to your server and then insert the totals into the web page when the ajax call returns the data.

Categories

Resources