in reply to Re: Separate Javascipt code from pure Perl code
in thread Separate Javascipt code from pure Perl code

Firsly a HUGE thanks to you shmem for being able to understand EXACTLY my needs and also willing to help me implement it! I want you to knwo that i really apreciate your help given a great deal!

I used the above snippet inside my index.pl but unfortunately non of the 2 javascripts seems to appear(called), down kno why, youc an check them though by going to http://nikos.no-ip.org
It seems that you want to set a variable for your char_by_chars.js script file.
Yes, exactly! This is a cool javascript displaying the contents of variable $data character_by_character. So you can see why it is essential for me to pass this variable from index.pl => char_by_char.js

Also variables must be passed to the othe script you have made yourself for helping me(you know the i liek it to call it orderlist js) so to be functional. So we also have to pass values there....

ps. Do the javascript files are the first thing that gets executed when index.pl loads? if yes, by what order? And also if they are then how do they contain the correct value of $data showing in the following code, which is presented later on index.pl?!?
print a( {href=>'/cgi-bin/register.pl'}, img{src=>'/data/images/reg.j +pg'} ); my @userlist = @{ $db->selectcol_arrayref("SELECT username FROM users" +) }; print start_form( action=>'/cgi-bin/index.pl' ); print h1( {class=>'lime'}, "Κάνε LOGIN γ +ια να δεις τις + παραγγελίες & +#963;ου μέχρι στι&# +947;μής => ", popup_menu( -name => 'userlogin', -val +ues => \@userlist ), submit('Σύνδε +ση!')); print end_form; my $userlogin = param('userlogin'); if ( param('Σύνδεση!') ) { unless( grep { $_ eq $userlogin } @userlist ) + #Check if userlogin name exists in the drop down menu { print br() x 2, h1( {class=>'big'}, "Δεν υ +πάρχει χρήστ&# +951;ς με όνομα: $userlogin" ) +; exit; } $select = $db->prepare( "SELECT counter, host, DATE_FORMAT(date, ' +%a %d %b, %h:%i') AS date FROM guestlog WHERE username=?" ); $select->execute( $userlogin ); $row = $select->fetchrow_hashref; if( $select->rows ) { $data = "Καλώς ήλθ&#94 +9;ς $userlogin! Χαίρομαι + που βρίσκεις +την σελίδα εν& +#948;ιαφέρουσα. Τελευταί&#945 +; φορά ήρθες ε&#948 +;ώ ως $row->{host} στις $row->{dat +e} ! Προηγούμ&#949 +;νος αριθμών ε +πισκέψεων => $row->{coun +ter} Τί θα πάρε&#9 +53;ς σήμερα !?"; $select = $db->prepare( "UPDATE guestlog SET username=?, count +er=counter+1, date=? WHERE host=?" ); $select->execute( $userlogin, $date, $host ); } } else { if( $host eq "Νίκος" ) { $data = "Γειά σου Ν&#9 +53;κόλα! Πώς πάν&#9 +49; τα κέφια? ;-)"; } else { $data = "Γειά σου $host! Έρχεσαι &#947 +;ια 1η φορά εδώ !! Ελπίζω να &#946 +;ρείς όλο το λ&#959 +;γισμικό που ε +πιθυμείς :-)"; } unless( $host eq "Νίκος" ) { $select = $db->prepare( "INSERT INTO guestlog (username, count +er, host, date) VALUES (?, ?, ?, ?)" ); $select->execute( 'Guest', 1, $host, $date); } }

Replies are listed 'Best First'.
Re^3: Separate Javascipt code from pure Perl code
by shmem (Chancellor) on May 07, 2007 at 21:43 UTC
    ps. Do the javascript files are the first thing that gets executed when index.pl loads? if yes, by what order?

    Yes, JavaScript is parsed and executed at load time. And it is executed in the order it appears.

    And also if they are then how do they contain the correct value of $data showing in the following code, which is presented later on index.pl?!?

    Simple - they don't. If you want to assign data to a JavaScript variable with the technique I showed you, the data must be available beforehand. Once you have output your start_html, the data you aquire later in your script doesn't travel after the output already written, overtaking it and magically inserting itself into the place you want it to be. You will have to re-organize your index.pl.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
    A reply falls below the community's threshold of quality. You may see it by logging in.