BlasTech
11-09-2004, 09:21 AM
I've created a page that asks my user a bunch of random questions which are generated by some javascript. The questions are created in a form which is passed via post to a php page which handles all the information. I need to pass a variable that holds the numbers associated with the random questions so that I can access it later. I've got everything working, except for one problem. If the user hits the 'Refresh' or 'Reload' button on their browser the form is reloaded, which changes the random questions that are generated, but the variable that held the originally generated numbers stays the same. I need to know how to make the variable reset and get the new numbers if the user hits the refresh button. The variable and associated form field is located in this snippet of my code:
//function to put the random numbers into the form field seperated by a '-'
function store_questions()
{
var w = 0;
for(w=0; w<15;w++)
{
document.random_question.storage.value += used[w] + '-';
}
}
I need the document.random_question.storage.value to reset itself with the new numbers from used[w] that will come with the refresh. Currently with any refresh it keeps the original numbers that came with the form the first time it was created. Any ideas?
If the user just fills out the form without any refresh it works fine. As soon as they refresh it screws everything up.
Here is the part of the code that creates the form if that is of any help:
<form method="POST" action="random_questions.php" name="random_question">
<textarea name="description" cols="60" rows="2"></textarea><br><br>
<script type="text/javascript">
for (i=0;i<15;i++)
{
//write out the correct random question
document.write(random_nonrepeating_text[used[i]]);
//call to the function that will write out the form field
write_form();
}
</script>
<!-- this hidden field will hold the numbers of the questions the user has answered and will be uploaded to the script with the form-->
<input type ="hidden" name = "storage">
<script type="text/javascript">store_questions();</script><br>
<input type="submit" value="Press to Answer">
Thanks,
BlasTech
//function to put the random numbers into the form field seperated by a '-'
function store_questions()
{
var w = 0;
for(w=0; w<15;w++)
{
document.random_question.storage.value += used[w] + '-';
}
}
I need the document.random_question.storage.value to reset itself with the new numbers from used[w] that will come with the refresh. Currently with any refresh it keeps the original numbers that came with the form the first time it was created. Any ideas?
If the user just fills out the form without any refresh it works fine. As soon as they refresh it screws everything up.
Here is the part of the code that creates the form if that is of any help:
<form method="POST" action="random_questions.php" name="random_question">
<textarea name="description" cols="60" rows="2"></textarea><br><br>
<script type="text/javascript">
for (i=0;i<15;i++)
{
//write out the correct random question
document.write(random_nonrepeating_text[used[i]]);
//call to the function that will write out the form field
write_form();
}
</script>
<!-- this hidden field will hold the numbers of the questions the user has answered and will be uploaded to the script with the form-->
<input type ="hidden" name = "storage">
<script type="text/javascript">store_questions();</script><br>
<input type="submit" value="Press to Answer">
Thanks,
BlasTech