Injecting JavaScript

Last Updated: 9/16/2008



Sections above here:
Home  »  Development  »  Javascript

Sections below here:

    Topics in this section:
    Overview
    Areas of Implementation
    Using Script Events
    Writing JavaScript Events
    More Script Events
    Javascript Functions
    Injecting JavaScript
    Hidden Fields
    Down Loading a File
    JavaScript Solutions

    Search Documentation:

    Besides using the ScriptEvents property of IntraWeb Controls, there are multiple other possibilities to add JavaScript to your pages.

    IWForm.JavaScript Property

    This is the most native method to add JavaScript functions to your pages. Always add JavaScript enclosed with a <script> tag: 

    <script language="Javascript1.2">
    function CheckLength(ASender)
    {
    if (ASender.value.length < 6)
    {
    alert("Type more characters.");
    }
    }
    </script>

    Using the above code you can use CheckLength() in other ScriptEvents.

    IWForm.ExtraHeader Property

    The IWForm.ExtraHeader property can be used to specify extra content to be inserted in the <HEAD> section of the resulting HTML document.

    AddToInitProc


    IW Forms and controls have AddToInitProc property which adds JavaScript code to be executed immediately after the browser loads the HTML. You can easly access your application variables in JavaScript if include them into AddToInitProc.For example:

    procedure TIWForm1.IWAppFormCreate(Sender: TObject); 
    resourcestring
    VerNum = '101010';
    begin
    AddToInitProc('window.alert("Load version '+
    VerNum+
    '")')
    end;

    This code will result in alert window appear when browser loads your application.


    AddValidation

    AddValidation is an convenient way to add certain validation checks to your page before it gets submitted back to the server. For example to prevent users from submitting a form with blank IWEdits you could write IWForm.IWAppFormRender event handler as below:

    procedure TIWForm1.IWAppFormRender(Sender: TObject); 
    var
    j : integer;
    begin
    for j:=0 to ComponentCount-1 do
    if Components[j] is TIWEdit then
    with TIWEdit(Components[j]) do
    begin
    AddValidation(HTMLName+'IWCL.value.length==0',
    'You cannot leave '+FriendlyName+' empty')
    end;
    end;

    If the validation condition is true (IWCL.value.length==0), then the page will not submit and the validation message will be shown instead.



    (C) 2002-2009 - Atozed Software Ltd.