I'm specifically talking about the IE embedded script language "PerlScript" from ActiveState.
I currently have the following, but when button 3 is pressed, no action happens.
<html>
<head>
<title>perlscript baby!</title>
</head>
<script language="perlscript" event="onload" for="window">
sub yawn
{
$window->alert("hi!");
}
sub createNew
{
$b = $window->document->createElement('button');
$b->{value} = "button 3";
$b->{onclick} = "yawn()";
$window->alert("Button: " . $b->{outerHTML});
$window->document->body->appendChild($b);
}
sub enable
{
undef $window->document->all('buttn 2')->{disabled};
}
</script>
<body>
<input id='enabler' type='button' value='button 1' onclick='enable()'></input>
<input id='action' type='button' value='button 2' disabled onclick="createNew()"></input>
</body>
</html>
This is a very difficult thing to achieve, apparently. The browser (IE9 in my case) is expecting the value of the
onclick
attribute (when set from a script) to be a function reference rather than a string. We can prove this by converting your code into the equivalent JavaScript as shown below.If we run this, the third button will appear, but clicking it will do nothing. We need to make only a minor adjustment to make this work in JavaScript.
Now, if we convert this back to the equivalent perlscript, we can see that it still doesn't work.
In fact, it's a little bit worse because now, if you use your favourite HTML debugger to inspect the button 3 element, there is no
onclick
handler at all. So what can we do to get around this? Well, the answer is actually pretty simple - don't use PerlScript to create the elements dynamically, instead, create them statically and use PerlScript to hide and show them.This seems to do the job nicely, although I'm not sure how well it will fit into your use case. There is of course, one massively weird thing in this code: the
onclick
handlers for each of theinput
elements explictly states that it is calling a JavaScript function. This is not true, obviously, as those functions are actually PerlScript subroutines. However, if you remove thejavascript:
prefix, then the handlers are never called. I think this just further highlights the browser's bias towards JavaScript.Hope that helps!