JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 19th, 2004, 10:48 AM
armysierra armysierra is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 armysierra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Problem on auto submit a form, it only refreshes the page

hi,

i am trying to submit a form having two(2) submit type in a form, NEXT and SUBMIT_NOW buttons, if the timer is up and consumed, the NEXT button or SUBMIT_NOW button will be pressed automatically. here's my timer code:

Code:
 

<script LANGUAGE="Javascript"><!--
 function go_on() 
 {

 document.test.submit();
  }
 
 var i=60; 
 function countDown() 
 {
 if(i >= 0)
 {
   document.frm.clock.value=i;
   i = i-1;
   var c = window.setTimeout("countDown()", 1000);
 }
 else 
 {
   go_on();
 }
 }
//--></SCRIPT>
</head>

<body onLoad="countDown()"  <?php if (isset($ionload)) echo $ionload; ?>>
 <table width="100%">...



If I put the Javascript on a single page (for testing) and don't use $PHP_SELF[see below code], it works, but I need to make this work using $PHP_SELF coz my list of question is randomly drawn within the page.

With my existing code (Javascript & the PHP below), it only refreshes the page and not moving on to the next question or even submit the entire test. Can you check the code where I could fix the problem?


PHP Code:
require_once('./include/h.inc.php');
    
pt_register('GET''question_id');
    
pt_register('POST''submitname''questions''question_id''question_number''prev''next');
    
pt_register('SESSION''test_session');

    
$question_count count($test_session->questions) - 1;

    if (isset(
$next)) {

        foreach(
$questions as $question_id => $answer) {
            list(
$test_session->answers[$question_number]) = pt_clean_vars($answer);
        }

        
$next_question_id $test_session->questions[$question_number 1];
        
pt_redirect("question.php?question_id=$next_question_id");
    }

    if (isset(
$prev)) {

        foreach(
$questions as $question_id => $answer) {
            list(
$test_session->answers[$question_number]) = pt_clean_vars($answer);
        }

        
$prev_question_id $test_session->questions[$question_number 1];
        
pt_redirect("question.php?question_id=$prev_question_id");
    }


    if (isset(
$submitname)) {

        
// make sure to update the answer into our test_session var
        
foreach($questions as $question_id => $answer) {
            list(
$test_session->answers[$question_number]) = pt_clean_vars($answer);
        }

        
$count 0;
        
// now, we need to reconstruct the questions array in a format that
         
foreach ($test_session->questions as $question_id) {
            
$questions[$question_id] = $test_session->answers[$count++];
        }

        
// instantiate the test object so we can grade the test
        
$test = new cTest($test_session->test_id);

        
$test->grade($questions);
        
pt_redirect("view_results.php?user_id=$user->user_id&feedback=" urlencode($strings['TEST_SCORED']));
    } else {
        require_once(
'./include/header.inc.php');
 
        
// figure out which question number we are on.
        
$question_number array_search($question_id$test_session->questions);
 
        if (
$question_number === FALSE) {
            
pt_exit('Fatal Error: unable to determine question number.');
        }

        
// output test title and additional notes
        
echo "<div class=\"form\"><center><b>{$test_session->info['description']}</b></center>";
        

        if (
$test_session->info['notes']) {
            echo 
"<hr noshade=\"noshade\" size=\"1\" />";
            echo 
"<div class=\"small\">{$test_session->info['notes']}<center><form name=\"frm\"><font size=-1>You have 180 seconds to answer this question:<input type=\"text\" name=\"clock\" size=2></font></form></centre></div>";
        }
        
        echo 
"</div>";
        echo 
"<form method=\"post\" name=\"test\" action=\"$PHP_SELF\">";
        echo 
"<div class=\"test\">\n";
        
        
//lugar ng Q , Image/Flash, QOptions
        
echo "<table border=0 width=\"100%\" cellspacing=\"0\" cellpadding=\"10\">";

        
draw_question($question_id);
 
        echo 
"</table>";
        echo 
"</div>";
        echo 
"<input type=\"hidden\" name=\"question_number\" value=\"$question_number\" />";
        echo 
"<input type=\"hidden\" name=\"question_id\" value=\"$question_id\" />";

 
        echo 
"<tr>\n";
        echo 
"<td align=center bgcolor=\"" pt_table_highlight(0) . "\">\n";
        
// show the previous button unless we're on the first question
        
if ($question_id != $test_session->questions[0]) {
            echo 
"<input type=\"submit\" name=\"prev\" value=\"<< {$strings['TEST_PREVIOUS_QUESTION']}\" />\n";
        }

        
// show the next button unless we're on the last question
        
if ($question_id != $test_session->questions[$question_count]) {
            echo 
"<input type=\"submit\" name=\"next\" value=\"{$strings['TEST_NEXT_QUESTION']} >>\" />\n";
        }

        echo 
"<input type=\"submit\"  name=\"submitname\" value=\"{$strings['TEST_SUBMIT']}\" />\n";
        echo 
"</td>\n";
        echo 
"</tr>\n";
        
        echo 
"</form>\n";
 

 
//echo "</table>";
        
echo "</div>";
        require_once(
'./include/footer.inc.php');
    } 


Your time and help will very much appreciated.

Army

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Problem on auto submit a form, it only refreshes the page


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT