Hello,
I have a perl file that generates an html file to use on a webpage. I have to add some javascript to the html part of the perl file.
I already have some code to do that, but here is the issue: the javascript needs to grab a parameter from the perl information.
eg., lets say I need to run javascript that uses a directory name for example, and that directory can change. So I cannot hardcode it...instead, I have a variable called $dir to store that information. How can I generate the javascript part and pass it the contents of $dir, so that the javascript points to the correct directory when executing?
Thanks
11 1543
if $dir is defined before the javascript is printed: -
<script language="JavaScript" type="text/javascript">
-
function foo() {
-
var dir = $dir
-
......
-
}
-
</script>
-
if $dir is not defined before the javascrpt gets printed I don't know how you can do it.
This is what I have.
So would your method work, ie adding var name = $someName in the execCmd function? - {print "Content-type:text/html\n\n";
-
-
$someName = "name";
-
$someUser = "user";
-
-
{
-
print <<EOS;
-
-
<head>
-
<title> TEST </title>
-
<style type="text/css">
-
<!--
-
.style1 {
-
color: #0000FF;
-
font-weight: bold;
-
font-size: 30px;
-
-->
-
</style>
-
-
<script type="text/javascript">
-
function execCmd()
-
{
-
var shell = new ActiveXObject("WScript.shell");
-
shell.run(''clt kpp Build \\"<someUser>\\" name- <someName>.ext');
-
}
-
</script>
-
</head>
-
-
<body onLoad = "execCmd()" alink = blue vlink = blue background = "../image/bkgr.jpg">
-
-
</body>
-
EOS
-
}
<someName> and <someUser> are the variables that need to change. Usually when I print stuff, I do print($someName . "random text" . $someUser . "\n");
Essentially, I need to do the samething in the execCmd. I need to replace <someName> and <someUser> with the perl equivalent ($someName...). So how would I do that?
Sorry mate, I'm not interested in helping people that cross-post their questions. Go read the replies on the other forum.
Hello,
I have a perl file that generates an html file to use on a webpage. I have to add some javascript to the html part of the perl file.
I already have some code to do that, but here is the issue: the javascript needs to grab a parameter from the perl information.
eg., lets say I need to run javascript that uses a directory name for example, and that directory can change. So I cannot hardcode it...instead, I have a variable called $dir to store that information. How can I generate the javascript part and pass it the contents of $dir, so that the javascript points to the correct directory when executing?
Thanks
Maybe you could use the CGI module.
Take a look at this example:
I define some variables in perl first.
Then print the header.
Then create a "here document" containing all the javascript that will occur up until the point that I want to include a perl variable.
When you want to include a perl variable terminate the here doc, and add the variable to the script scalar, in this case "$JSCRIPT".
Notice the ".=" (add to the existing scalar $JSCRIPT)
The add another here doc to $JSCRIPT until you want to add another perl variable.
Also notice that when I declared the perl variable I used "'...'" what I am doing is storing a set of single quotes within the perl variable, so that the javascript will not think that hey is an object. This may not be needed depending on what the context of the javascript is. If I where inserting something into javascript that didn't need to be a string, I wouldn't need the single quotes.
If you run this code you will find that it works.
The resulting page will create an alert that says "hey". -
#!/usr/bin/perl
-
-
use strict;
-
use warnings;
-
use CGI qw(:standard);
-
-
my $it = "'hey'";
-
print header();
-
-
my $JSCRIPT =<<SRC;
-
-
function doIt(){
-
-
alert(
-
SRC
-
$JSCRIPT .= $it;
-
-
$JSCRIPT .=<<SRC;
-
);
-
-
// some more code here
-
}
-
SRC
-
-
print start_html(-script=>$JSCRIPT,onload=>'javascript:doIt();');
-
-
print end_html();
-
The real power here comes from the CGI module.
It allows me to include the $JSCRIPT var into the head of the resulting page, also I am able to add an onload event to the body tag.
Read more about the CGI module HERE
Sorry mate, I'm not interested in helping people that cross-post their questions. Go read the replies on the other forum.
I wasn't aware that "cross-posting" questions is enough to annoy people. As far as I'm concerned, the more help/options that I can get the better. There is nothing wrong with this method of learning, which incidentally worked fantastically for me.
You're an expert at this, I'm not. The project that I'm working on was shoved into my pile before I knew what perl was, and this is really the only way I can pick up on the more advanced stuff. I was simply looking for different answers so that I'm able to pick the best method for the purposes of my project
I, just like you, surf more than one developer forum. I'm pretty sure if you had questions that you really need answers for, you'd do the same thing. I hope you understand where I'm coming from.
In any case, thanks for your initial reply. Kelicula:
As for the CGI module, I've been reading up on it and it seems like it's a perfect solution. I will need to use it for other cases eventually, so I might as well start learning it now. I haven't started the coding part, but your example is very well written and easy to understand. Thanks for all the help.
I wasn't aware that "cross-posting" questions is enough to annoy people. As far as I'm concerned, the more help/options that I can get the better. There is nothing wrong with this method of learning, which incidentally worked fantastically for me.
You're an expert at this, I'm not. The project that I'm working on was shoved into my pile before I knew what perl was, and this is really the only way I can pick up on the more advanced stuff. I was simply looking for different answers so that I'm able to pick the best method for the purposes of my project
I, just like you, surf more than one developer forum. I'm pretty sure if you had questions that you really need answers for, you'd do the same thing. I hope you understand where I'm coming from.
In any case, thanks for your initial reply. Kelicula:
As for the CGI module, I've been reading up on it and it seems like it's a perfect solution. I will need to use it for other cases eventually, so I might as well start learning it now. I haven't started the coding part, but your example is very well written and easy to understand. Thanks for all the help.
I think that the point KevinADC was trying to make was that you already had an answer to your question at the other forum where you posted the same question and was just letting you know that he wasn't going to provide the same answer here as it was already given.
Cross posting is mostly annoying to others when it happens and the person trying to provide the help sees that is has happened, yet the poster in question does not post to the other forums ( as a courtesy) that they have found an answer on another forum.
You have to look at things from an angle other than that of the person in need.
Regards,
Jeff
I think that the point KevinADC was trying to make was that you already had an answer to your question at the other forum where you posted the same question and was just letting you know that he wasn't going to provide the same answer here as it was already given.
Cross posting is mostly annoying to others when it happens and the person trying to provide the help sees that is has happened, yet the poster in question does not post to the other forums ( as a courtesy) that they have found an answer on another forum.
You have to look at things from an angle other than that of the person in need.
Regards,
Jeff
I understand that, but the questions were posted at the same time. The other forum simply got to the answer quicker.
In any case, I apologize for any inconvenience. Like I said, I take all suggestions, regardless of whether or not I solved the problems. I keep all the replies for future reference anyway. If a better solution comes along after a problem has been solved, I usually do change what I have to make it better.
I understand that, but the questions were posted at the same time. The other forum simply got to the answer quicker.
In any case, I apologize for any inconvenience. Like I said, I take all suggestions, regardless of whether or not I solved the problems. I keep all the replies for future reference anyway. If a better solution comes along after a problem has been solved, I usually do change what I have to make it better.
Think of it like this. You are in a room full of people all talking about the same thing. Someone walks in and asks a question of everyone there. All of the people in the room have the answer at the same time. Would you speak up and give the same answer as the rest of just go back to your discussion, knowing that the others have answered it the same as you would have.
That is how KevinADC feels and I back him up on that. Personally, I stick to the one forum at a time rule. If you know of a forum that will consistently answer your questions quicker (maybe due to a larger user base), then ask there first. Then, if no joy is received there, move on to another forum.
You will be suprised how many people take Kevins stance. I do!
Regards,
Jeff
If a better solution comes along after a problem has been solved, I usually do change what I have to make it better.
I think I have a better solution.
If you include the perl variables within the javascript in double quotes I think it will interpolate them for you.
ie: -
my $user = param('user');
-
my $time = localtime;
-
-
my $JSCRIPT = <<SRC;
-
-
-
var user ='"$user"';
-
-
document.theDiv.innerHTML = 'hello '+user+' I see it is '+"$time"+' oclock';
-
-
-
SRC
-
-
Once again I have added single quotes to tell jscript that it's a string, but this I put them on the outside, hoping that perl will interpolate the $user var, then encapsulate it in the singles.
(not always necessary)
Notice the double quoted $time var.
This code is untested though. I'm at work and can't try it out till I get home...
Hope it helps..
I wasn't aware that "cross-posting" questions is enough to annoy people. As far as I'm concerned, the more help/options that I can get the better. There is nothing wrong with this method of learning, which incidentally worked fantastically for me.
You're an expert at this, I'm not. The project that I'm working on was shoved into my pile before I knew what perl was, and this is really the only way I can pick up on the more advanced stuff. I was simply looking for different answers so that I'm able to pick the best method for the purposes of my project
I, just like you, surf more than one developer forum. I'm pretty sure if you had questions that you really need answers for, you'd do the same thing. I hope you understand where I'm coming from.
In any case, thanks for your initial reply.
Don't take it personally. My opinion about cross-posting a question on multiple forums is just that, it's mine. I see no reason to defend or explain my reasons to you or anyone else.
However, I do apologize for my other comment. I should not have told you to "go read the replies on the other forum". That was inappropriate of me and I am sure sounded very rude. I did not mean it to be rude, but I can see now that my words were poorly choosen and it was very inappropriate of me to tell you what to do.
You are free to post a question on as many forums as you like, and I am free to decide not to answer them.
My apology for being rude to you.
Kevin
No worries.
Kelicula: I'm trying that right now, I hope it works. The other things I tried did not end up working properly. The code is read, but the command isn't executed for some reason.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Xah Lee |
last post by:
# -*- coding: utf-8 -*-
# Python
# David Eppstein of the Geometry Junkyard fame gave this elegant
# version for returing all possible pairs from a range of n numbers.
def combo2(n):
return...
|
by: Tommo |
last post by:
Hello All,
I am a still learning so be easy on me. I am trying to get
some code to work that is using JS and Perl/CGI, I am using AS Perl
and an Apache Server on XP as the webserver. Can anyone...
|
by: Richard Trahan |
last post by:
I want a js function to call a Perl script residing on a server.
The Perl script will return a string, to be used by the js.
Pseudo code:
<script>
stringvar = perlfunc_on_server(stringarg)...
|
by: phal |
last post by:
Hi all;
I code Perl for CGI, I using regular expression to check the validation
of user input, because the form is small and it run only from my own
computer, anyways if many people using my...
|
by: Alex |
last post by:
I'm not exactly sure how to use these two languages together. It seems
to me that they both totally different things.
PERL = databases, heavy processing, server functions. But I can also
write...
|
by: shaun roe |
last post by:
I have a directory which contains many xml files as a result of some
analysis. I would like to have an XSL which loops over all these files
and generates a web page indicating some summary...
|
by: Nathan Gilbert |
last post by:
I am wanting to use javascript to select between different *.css files
dependent on the user's browser. I am also wanting to generate the
html document containing this javascript dynamically using...
|
by: John Passaniti |
last post by:
(Note: This is not the same message I posted a week or so ago. The
problem that prevented my previous attempt to work was a silly error in
the template system I was using. This is a problem...
|
by: happyse27 |
last post by:
Hi All,
I am creating the perl script using html form(with embedded javascript inside).
When using this html form with javascript alone, it works where the form validation will pop up...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |