I have a fairly simple web app built with Delphi (2009) Web Broker. I am trying (and failing) to output Javascript to the page.
The javascript I need to output is in the body of the page in a <form>
tag, and is as follows:
<script>DateInput('mydatefield', true, 'DD-MM-YYYY');</script>
This javascript should create a nice date input control (tested ok in a hand-crafted HTML page). The code in my Delphi app this is:
Response.Content := Response.Content + '<script>DateInput(''mydatefield'', true, ''DD-MM-YYYY'');</script>';
The Script tags are being removed from the final output.
As a test I added an HTML button with an onClick
event set as follows:
Response.Content := Response.Content + '<input type="button" onClick="alert(''Hello World'')" Value="Hello World"/>';
and when the source of the page is inspected
alert(''Hello World'')
had become
alert('Hello World')
I wondered if this translation of the single quote from ' into '
; might be causing my earlier script tag to be removed?
Any help/pointers appreciated, thanks.
* EDIT
I should point out that the Alert popup does work even with the '
characters.
* EDIT
I have tried to use JQuery scripts like $(document).ready( function() { etc }); and it's working, so I guess the problem is not with WebBroker output. Thanks to all who took time to read/think.
Try HTMLEncode unit HTTPApp:
Response.Content := Response.Content + HTMLEncode('...');