Reputation: 3075
Let's say I have a variable called $taskid
defined in <%init>
. Can I generate a JavaScript function from that variable?
<script language="javascript">
window.onload = function() {
alert("<% $taskid %>");
};
</script>
<%init>
my $taskid=1;
</%init>
Upvotes: 1
Views: 1844
Reputation: 3075
This worked:
<script language="javascript">
window.onload = function() {
alert("<% $taskid %>");
};
</script>
<%init>
my $taskid=1;
</%init>
Upvotes: 1
Reputation: 385764
Is it possible to initialize a JavaScript variable from Perl?
Since you asked that three times even though it has nothing to do with what you posted, I'll answer it.
No.
Languages can't take actions, much less initialize. A Perl program cannot do so either. A process cannot access variables a) in a different virtual machine, b) in a different process, c) on a different machine. All three apply here.
JavaScript variables can only be initialized by JavaScript assignments. You would need to either
Upvotes: 0