Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java+Perl syntax error 1

Status
Not open for further replies.

sulfericacid

Programmer
Joined
Aug 15, 2001
Messages
244
Location
US
The following code I'm playing with is:
qq(<SCRIPT LANGUAGE=&quot;JavaScript&quot;>),
Tr( td(),
td(submit),
td(&quot;document.write('<form><input type=button value=\&quot;Refresh\&quot; onC
+lick=\&quot;history.go()\&quot;></form>)&quot; ),
),
end_form(),
hr(),
qq(</script>)
);

print &quot;(<a href=\&quot;log.pl\&quot; target=\&quot;new\&quot;>chat logs</a>)&quot;;


Essentially what I'm trying to do is at a java refresh button beside my SUBMIT button inside the table. Debugger shows nothing wrong but when loading in the browser it says there's an error on the page [] and it doesn't load the JS button or my Submit button. Can anyone help me get the button to work?

&quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
Sulf,

You're mixing your html with JScript.

Build up your javascript code into a variable and then drop that into your cgi output at the relevant point.

$myvar=&quot;<script langauge=&quot;Javascript&quot;>
document.write('<form><input type=button value=\&quot;Refresh\&quot; onClick=\&quot;history.go()\&quot;></form>');</script></noscript>blah</noscript>&quot;;


Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
The problem is your td's are inside the script tag. Try removing the 1st and second to last lines.
 
PaulTEG, that's actually a great idea and it'll definately make that sequence of codes look cleaner using a variable instead of mixing everything into a glob. I tried your suggestion and it worked like a charm! I asked dozens of people the last two days and no one had any suggestions as to what's wrong with this and it's hard to believe that minutes after posting this on tek-tips someone like you already solved it.

The problem is solved and I don't wish to steal time away from everyone else that needs help but I was wondering why it would make a difference if I were using a variable or not (other than visual debugging purposes).

Thank you SO much for your help!

&quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
If you looked at your source as usige puts it, your tds are inside your script tags

<script language=javascript><td> <!-- see not valid javascript syntax

Besides it's just tidier that way using a variable, and not only for visual debugging, but for gathering the relevant script to package

Cheers
Paul

BTW - Whaddya mean someone like ME ...

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
I meant that I usually don't come here for perl help. I'm a member of and usually someone there knows how to fix something I messed up. There are some people on that page who helped write the series of Learning Perl so I expected him to be able to help, but he wasn't able to. It wasn't to come off as mean, I was just saying I'm suprised how quickly someone could solve a problem that he couldn't.

Can I ask one more small question? Right now I have: td(submit('send'), $js), but my chat script (the url should be on this page somewhere) doesn't reload as I thought it would after you send a message. How can I make it so after clicking the submit button it refreshes the page?

&quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
Sulf,

Had a quick look,

history.go() doesn't that mean go back one??

There are a few hippics in your HTML code, that number of &NBSP;'s just ain't right, and something's interfering with your font tag, because its not closing, before the palign=right directive (mebbe <p align=&quot;right&quot;>??, p({align=>&quot;right&quot;}, &quot;hello world&quot;) ....

Could you post your script to date?
When the page is submitted you should be generating based on all available data, which SHOULD deliver the desired result. I think maybe the javascript is causing the puppy to puke. If not there's bound to be a javascript function to reload the page, which can be made conditional based on a hidden field which is set depending on how the refresh or post is called

HTH
Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Ok, my guess is that the page is being cached. Since the URL doesn't change it appears to the browser that it is the same page. Try adding a no-cache pragma in the head:
Code:
<META HTTP-EQUIV=&quot;Pragma&quot; CONTENT=&quot;no-cache&quot;>
 
#!/usr/bin/perl -w

open( STDERR, &quot;>>/home/sulfericacid/public_html/error.log&quot; )
or die &quot;Cannot open error log, weird...an error opening an error log: $!&quot;;

use strict;
use warnings;
use POSIX;
use CGI qw(:standard start_table end_table);

use lib &quot;&quot;;
use Tie::IxHash;

require SDBM_File;

my %chat;
my %chatorder;
my $chat = &quot;list.dbm&quot;;
my $file = &quot;iplog.txt&quot;;

tie %chat, &quot;Tie::IxHash&quot;;
tie %chatorder, &quot;Tie::IxHash&quot;;

tie %chat, 'SDBM_File', $chat, O_CREAT | O_RDWR, 0644;
if ( !tied %chat ) {
print &quot;database unsuccessful $!.\n&quot;;
}

$| = 1; # maybe this will help page refreshing

my $js = &quot;<script langauge=\&quot;Javascript\&quot;>
document.write('<form><input type=button value=\&quot;Refresh\&quot; onClick=\&quot;history.go()\&quot;></form>');</script></noscript></noscript>&quot;;

print header, start_html;

#
# Time to keep accurate logs
#
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
localtime(time);
print &quot;the local time is $hour:$min:$sec&quot;;

print start_table;
print Tr(
td(
{ -height => '5', width => '700', bgcolor => '#BBCCEE' },
&quot;<font size=2><b>ChatterBox version 1.0</b></font>&quot;
)
);
print Tr( td( { -height => '5', width => '700', bgcolor => '#BBCCEE' }, &quot;&quot; ) );

my $add;

foreach ( reverse keys(%chat) ) {
$add++;

if ( $add <= 10 ) {
$chatorder{$_} = $chat{$_};
}
}

foreach ( reverse keys(%chatorder) ) {
my ( $name, $message, $time ) = split /::/, $chatorder{$_};
print Tr(
td(
{ -width => '700' },
&quot;<font color=blue>$name @ $time:</font> $message&quot;
)
),
;
}
print Tr( td( { -height => '5', width => '700', bgcolor => '#BBCCEE' }, &quot;&quot; ) );
print Tr(
td(
{ -height => '5', width => '700', bgcolor => '#BBCCEE' },
&quot;<font size=2 palign=right><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )
);

print start_form(), table(
Tr(
td(&quot;Name: &quot;),
td(
textfield(
-name => 'name',
-size => 40
)
)
),
Tr(
td(&quot;Message: &quot;),
td(
textfield(
-name => 'message',
-size => 100,
-force => 1,
)
)
),

Tr( td(), td( submit('send'), $js ), ),
end_form(),
hr(),
);

print &quot;(<a href=\&quot;log.pl\&quot; target=\&quot;new\&quot;>chat logs</a>)&quot;;

my $name = param('name');
my $message = param('message');
my $cnt;

if (param) {
if ($name) {
if ($message) {

open( LOG, &quot;$file&quot; );
$cnt = <LOG>;
close(LOG);

$cnt++;
open( LOG, &quot;> $file&quot; );
print LOG $cnt;
close(LOG);

my $keeptime = join ( ':', $hour, $min, $sec );
my $info = join ( '::', $name, $message, $keeptime );

$chat{$cnt} = $info;
}
else {
print &quot;Message was missing, data not sent.<br>&quot;;
}
}
else {
print &quot;Name was missing, data not sent.<br>&quot;;
}
}



&quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
I noticed that the refresh button isn't doing as it's supposed to but I was told that's the way to refresh the page. I tried adding the meta line but it still won't refresh after you click SUBMIT.

&quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
&quot;<font size=2 palign=right><b>

should read as <font size=&quot;2&quot;><p align=&quot;right&quot;><b>

But that's not relevant to the refresh issue.

Aha, it looks like its not a refresh issue.

Write to the DBM file before generating the output.

HTH
--Paul



It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Ok for the reload try changing your onclick to the following:
Code:
 onclick=&quot;window.location.reload()&quot;
I'm not seeing the meta tag in the document head. You can also try:
Code:
print header(-expires => '-1d'), start_html;
 
Sulf,

Did that sort it out?

Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Sorry about the wait, I've been away most of the evening. Changes I have made: I redid the p align tag which meant I didnt' have to use a block of 100 & nbsp; codes. I used the suggestion as the new OnClick event for the refresh button but that still doesn't seem to work. But for the suggestion on the time code, I think that'll be left the same since that's one of the few things that actually work right now.

Paul, I tried your last suggestion (which makes a lot of sense) but the same problem arises. My current code is below incase the idea is right and I'm just doing something silly.

Thanks guys!


#!/usr/bin/perl -w

open( STDERR, &quot;>>/home/sulfericacid/public_html/error.log&quot; )
or die &quot;Cannot open error log, weird...an error opening an error log: $!&quot;;

use strict;
use warnings;
use POSIX;
use CGI qw(:standard start_table end_table);

use lib &quot;&quot;;
use Tie::IxHash;


require SDBM_File;

my %chat;
my %chatorder;
my $chat = &quot;list.dbm&quot;;
my $file = &quot;iplog.txt&quot;;

tie %chat, &quot;Tie::IxHash&quot;;
tie %chatorder, &quot;Tie::IxHash&quot;;


tie %chat, 'SDBM_File', $chat, O_CREAT | O_RDWR, 0644;
if ( !tied %chat ) {
print &quot;database unsuccessful $!.\n&quot;;
}



$|=1; # maybe this will help page refreshing

my $js=&quot;<script langauge=\&quot;Javascript\&quot;>
document.write('<form><input type=button value=\&quot;Refresh\&quot; onClick=\&quot;window.location.reload()\&quot;></form>');</script></noscript></noscript>&quot;;

# Time to keep accurate logs
#
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);



print header, start_html;


my $name = param('name');
my $message = param('message');
my $cnt;


if (param) {
if ($name) {
if ($message) {

open( LOG, &quot;$file&quot; );
$cnt = <LOG>;
close(LOG);

$cnt++;
open( LOG, &quot;> $file&quot; );
print LOG $cnt;
close(LOG);

my $keeptime = join (':', $hour, $min, $sec);
my $info = join ( '::', $name, $message, $keeptime );

$chat{$cnt} = $info;
}
else {
print &quot;Message was missing, data not sent.<br>&quot;;
}
}
else {
print &quot;Name was missing, data not sent.<br>&quot;;
}
}


print &quot;(<a href=\&quot;log.pl\&quot; target=\&quot;new\&quot;>chat logs</a>)&quot;;



print &quot;the local time is $hour:$min:$sec&quot;;


print start_table;
print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},&quot;<font size=2><b>ChatterBox version 1.0</b></font>&quot; ));
print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},&quot;&quot;));

my $add;

foreach (reverse keys (%chat)) {
$add++;

if ($add <= 10) {
$chatorder{$_} = $chat{$_};
}
}

foreach (reverse keys (%chatorder)) {
my ( $name, $message, $time ) = split /::/, $chatorder{$_};
print Tr(td({-width=>'700'},&quot;<font color=blue>$name @ $time:</font> $message&quot;)),
}
print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},&quot;&quot;));
print Tr(td({-height=>'5', width=>'700', bgcolor=>'#BBCCEE'},&quot;<font size=2><p align=right><b> ));


print start_form(), table(
Tr(
td(&quot;Name: &quot;),
td(
textfield(
-name => 'name',
-size => 40
)
)
),
Tr(
td(&quot;Message: &quot;),
td(
textfield(
-name => 'message',
-size => 100,
-force=>1,
)
)
),

Tr( td(),
td(submit('send'), $js),
),
end_form(),
hr(),
);









&quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
Actually the problem is solved now :) Someone suggested that I add an $action attribute to the form like this start_form(-action=>$url), ($url is the chat page). With the action attribute it appears it actually reloads the entire page and it displays what was just updated. []. Thanks so much for your help everyone!

sulfericacid

&quot;Age is nothing more than an inaccurate number bestowed upon each of us at birth as just another means for others to judge and classify us- sulfericacid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top