in reply to Re: Loading a web page automatically
in thread Loading a web page automatically

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: Loading a web page automatically
by Utilitarian (Vicar) on Jul 14, 2009 at 08:44 UTC
    Well you could use a templating system such a Mason;)
    Though if page1 is a form with
    <input type="hidden" name="next_page" value="/quiz/page2.html">
    and you grab the next_page parameter in your script, then print a 302 redirect directive as described above, the browser should load the next page.

    Alternatively you could have several hidden divs and change the style of the completed one to display: none; using Javascript, there are many ways to go about this as ever.

    What does the code, HTML and Perl that you've tried look like?
    What response do you see, in the browser?, in your server logs?

    Javascript form example

    <html> <head> <title>Invisible divs</title> <script> function showDiv(nextDiv) { for ( var divNum = 0; divNum < 4; ++divNum ) // Change 4 to suit n +umber of divs in page { var currentDiv = document.getElementById("div" + divNum); currentDiv.style.display = ( currentDiv.id == nextDiv ) ? "blo +ck" : "none"; } } </script> </head> <body onload="showDiv('div0');"> <!-- change action below to suit your needs--> <form action="/cgi-bin/assesTest.pl"> <div id="div0" style="display: none;"> This will be the only bit visible at first <a href="#" onclick="showDiv('div1')">Next &gt;</a> </div> <div id="div1" style="display: none;"> This will be visible after clicking on the link at the end of the firs +t div <a href="#" onclick="showDiv('div2')">Next &gt;</a> </div> <div id="div2" style="display: none;"> This will be visible after clicking on the link at the end of the seco +nd div <a href="#" onclick="showDiv('div3')">Next &gt;</a> </div> <div id="div3" style="display: none;"> This is the last element to display <input type="submit"> </div> </form> </body> </html>
      Thanks for the sustained interest in my ignorance.

      I have attached the code in my earlier response. The server log is withour any error, while the browser shows

      Status: 302 Moved Location: 127.0.0.1/loc.htm

      I am not at all conversant with java

      If you want I can attach the webpage, but please guide how to attach html on this message board. Or any other way to do it

        We all start in ignorance, that's what makes it fun ;)
        I should have made my advice clearer Status:302 is a HTTP directive to redirect the browser to another page It is used in place of the usual header see Corion's post above.
Re^3: Loading a web page automatically
by Corion (Patriarch) on Jul 14, 2009 at 08:17 UTC

    How do you expect us to suggest something else when you don't tell us how it doesn't work for you?

      Oh Yes! I have not made what is not working and I shall try to be more explicit now. The given code

      print "Status: 302 Moved\nLocation: $next_page\n\n";

      It only displays the line "Status: 302 Moved" and gives the url of the location

      I want to DISPLAY the new page and not simply tell its location to my students.

      The code which I have developed is

      #!/usr/bin/perl -w use CGI qw(:standard); #use Fcntl qw(:flock :seek); my $outfil = "as.txt"; if (param('RespName')) {} else {&dienice("Name");} if (param('Q1')) {} else {&dienice("You did not answer Q1");} if (param('Q2')) {} else {&dienice("You did not answer Q2");} $next_page = "127.0.0.1/loc.htm"; if (param('Q1')) {open(OUT, ">>$outfil"); flock(OUT, 2); seek(OUT, 0, 2); print OUT (param(RespName), param(Q1),param(Q2), "\n"; close(OUT)} print header; print start_html("Thank You"); print ("<Center>"); print ("Thank You ", param('RespName')," for your responses.! ", "\n < +/center> \n<BR>" ); print "Status: 302 Moved\nLocation: $next_page\n\n"; print (" </center> \n<BR>"); print end_html; sub dienice { my($msg) = @_; print header; print start_html("Error"); print h2("Sorry !"); print $msg; print end_html; exit}

      I suppose I have made it clear what is not working and appreciate any help.

      Thanks

        Ah hah - that makes it really easy. Instead of doing:

        print header; print start_html("Thank You"); print ("<Center>"); print ("Thank You ", param('RespName')," for your responses.! ", "\n < +/center> \n<BR>" );

        do

        print "Status: 302 Moved\r\nLocation: $next_page\r\n\r\n";

        and nothing else. This should instruct the receiving browser to move to $next_page. You might or might not have to output HTTP/0.9 302 Moved\r\n before that too, in the case of a redirect, depending on whether your web server handless that or not.