Link to home
Start Free TrialLog in
Avatar of remcogoris
remcogoris

asked on

Javascript variable declaration

Hi!

I am not an expert at all in javascript, so this is a simple question (i hope)

How do I create/declare variables in javascript?
In the code below, I get a Javascript error on the first line in function Minimize()
The error says that window.document.frmCloseSetting.itflag.value is null or is not an object.

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
      var windowX=100;
      var windowY=100;
      var windowWidth=400;
      var windowHeight=300;
      var autocenter = true;
      var autoclose = false;
      var beIE=document.all?true:false;

      function setMesg(){
         mess = "Warning: Only click OK if you are terminating your forms application. Clicking OK while Forms application is up and running will result in the loss of your session!"
         if (window.document.frmCloseSetting.itflag.value==0)
           return mess;
         else  
         return;    
      }
     
      function Minimizee() {
          window.moveTo(10000,10000);
          window.blur();
          window.onfocus = new Function("window.moveTo(10000,10000);");
      }

      function MinimizeIt() {
          window.document.frmCloseSetting.itflag.value=1;
          Minimizee();
          window.document.frmCloseSetting.itflag.value=0;
      }

      function CloseIt() {
         
          window.document.frmCloseSetting.itflag.value=0;
          window.close();
      }
-->
</SCRIPT>

Thanks!
Remco
Avatar of NicksonKoh
NicksonKoh
Flag of Singapore image

Hi,

Spelling error in function

function Minimizee() {

should be

function Minimize() {

Cheers
Nickson
Hi,

Sorry, after looking carefully, the script consistently calls Minimizee().

As for declaring variables, it's as simple as saying
   var myVariableName

just like in your code e.g.
   var windowX=100


As for the error, it's because the script cannot find the object with name itflag in your HTML form. Make sure you have such a object in your HTML form. Sth like

<input name="itflag" type="hidden" id="itflag" value="1">

Cheers
Nickson
Avatar of Michel Plungjan
It looks like you are trying a lot of stuff at times where the browser may or may not respond or allow you.

You cannot rely on a form field being present in a page in a function your call onUnload for example

Michel
Do it like this:

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
var winMin = false;

      function MinimizeIt() {
          winMin = true;
          Minimizee();
          winMin = false;
      }





Avatar of remcogoris
remcogoris

ASKER

Hm. Thanks for your reactions.
I have tried
   <input name="itflag" type="hidden" id="itflag" value="1">

But the same error occurs. Has to do with the place of the code relative to the javascript code?

As for Zvonko's suggestion: I haven't tried it yet, because I think the problem is, that the variable value isn't persistent. I will add the full html code, hoping this will clarify its use. An Oracle Forms applet is started by this page - the applet is opened in a separate window. I am trying to arrive at a situation where an end-user is able to 'minimize' the hosting browser-window to a position where it cannot be seen, AND where the end-user is warned when closing the browser-window, that she will also close the actual application (applet).

<HTML>
<!-- FILE: webutiljini.htm (Oracle Forms)                           -->
<!--                                                                -->
<!-- This is the a HTML template file for running a form on the     -->
<!-- web using JInitiator-style tags to include the Forms applet.   -->
<!-- and a certificate regsitration applet for the WebUtil utility  -->
<!--                                                                -->
<!-- IMPORTANT NOTES:                                               -->
<!-- Default values for all the variables which appear below        -->
<!-- (enclosed in percent characters) are defined in the servlet    -->
<!-- configuration file (formsweb.cfg). It is preferable to make    -->
<!-- changes in that file where possible, rather than this one.     -->
<!--                                                                -->
<!-- This file uses several extra tags that are not present in the  -->
<!-- default template files.  You should ensure that these are      -->
<!-- present in the configuration that uses this template           -->
<!-- The extra substitution Tags are:                               -->
<!--  %webUtilArchive% = jar file containing the WebUtil code       -->
<!--                     (by default this should be frmwebutil.jar) -->
<!--  %WebUtilLogging% = Defines the current logging mode.          -->
<!--                     Valid values: off|on|console|server|all    -->
<!--                     (on == console)                            -->
<!--  %WebUtilLoggingDetail% = Specifies the level of error logging.-->
<!--                     Valid values: normal|detailed              -->
<!--  %WebUtilErrorMode% = Should errors be displayed in an alert   -->
<!--                     as well as the programmer defined          -->
<!--                     locations                                  -->
<!--                     Valid values: console|server|alert|all     -->
<!--  %WebUtilDispatchMonitorInterval% = Counts in second to        -->
<!--                     indicate how often the monitor thread      -->
<!--                     checks to see if the Forms session is still-->
<!--                     alive. Used with the WebUtil_Session       -->
<!--                     package.                                   -->
<!--  %WebUtilTrustInternal% = Should intranet without domain suffix-->
<!--                     be trusted.                                -->
<!--                     Valid values: true|yes|false|no            -->
<!--  %WebUtilMaxTransferSize% = Size in bytes of file transfer     -->
<!--                     segments. Default and maximum allowed is   -->
<!--                     16384, i.e. 16K.                           -->


<HEAD><TITLE>%pageTitle% - WebUtil</TITLE>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
     
      var windowX=100;
      var windowY=100;
      var windowWidth=400;
      var windowHeight=300;
      var autocenter = true;
      var autoclose = false;
      var beIE=document.all?true:false;
     
      function setMesg(){
         mess = "Warning: Only click OK if you are terminating your forms application. Clicking OK while Forms application is up and running will result in the loss of your session!"
     if (window.document.frmCloseSetting.itflag.value==0)
           return mess;
         else  
         return;  
      }
     
      function Minimizee() {
          window.moveTo(10000,10000);
          window.blur();
          window.onfocus = new Function("window.moveTo(10000,10000);");
      }

      function MinimizeIt() {
          window.document.frmCloseSetting.itflag.value=1;
          Minimizee();
          window.document.frmCloseSetting.itflag.value=0;
      }

      function CloseIt() {
         
          window.document.itflag.value=0
          window.document.frmCloseSetting.itflag.value=0;
          window.close();
      }
-->
</SCRIPT>
<noscript> JavaScript is not enabled in your Browser. </noscript>
</HEAD>

<BODY %HTMLbodyAttrs% scroll="no" onbeforeunload="return setMesg()">
%HTMLbeforeForm%

  <input name="itflag" type="hidden" id="itflag" value="1">
  <a href="javascript:MinimizeIt()">Minimize</a>

<!-- Registration applet definition (start) -->
<OBJECT classid="%jinit_classid%"
        codebase="/forms/jinitiator/%jinit_exename%"
        WIDTH="0"
        HEIGHT="0"
        HSPACE="0"
        VSPACE="0">
<PARAM NAME="TYPE"       VALUE="%jinit_mimetype%">
<PARAM NAME="CODEBASE"   VALUE="%codebase%">
<PARAM NAME="CODE"       VALUE="oracle.forms.webutil.common.RegisterWebUtil" >
<PARAM NAME="ARCHIVE"    VALUE="%webUtilArchive%" >
<COMMENT>
<EMBED SRC="" PLUGINSPAGE="%jinit_download_page%"
        TYPE="%jinit_mimetype%"
        java_codebase="%codebase%"
        java_code="oracle.forms.webutil.common.RegisterWebUtil"
        java_archive="%webUtilArchive%"
        WIDTH="1"
        HEIGHT="1"
        HSPACE="0"
        VSPACE="0"
>
<NOEMBED>
</COMMENT>
</NOEMBED></EMBED>
</OBJECT>
<!-- Registration applet definition (end) -->

<!-- Forms applet definition (start) -->
<OBJECT classid="%jinit_classid%"
        codebase="/forms/jinitiator/%jinit_exename%"
        WIDTH="%Width%"
        HEIGHT="%Height%"
        HSPACE="0"
        VSPACE="0">
<PARAM NAME="TYPE"       VALUE="%jinit_mimetype%">
<PARAM NAME="CODEBASE"   VALUE="%codebase%">
<PARAM NAME="CODE"       VALUE="oracle.forms.engine.Main" >
<PARAM NAME="ARCHIVE"    VALUE="%archive_jini%,%webUtilArchive%" >

<PARAM NAME="serverURL" VALUE="%serverURL%">
<PARAM NAME="networkRetries" VALUE="%networkRetries%">
<PARAM NAME="serverArgs"
       VALUE="%escapeParams% module=%form% userid=%userid% sso_userid=%sso_userid% sso_formsid=%sso_formsid% sso_subDN=%sso_subDN% sso_usrDN=%sso_usrDN% debug=%debug% host=%host% port=%port% %otherParams%">
<PARAM NAME="separateFrame" VALUE="%separateFrame%">
<PARAM NAME="splashScreen"  VALUE="%splashScreen%">
<PARAM NAME="background"  VALUE="%background%">
<PARAM NAME="lookAndFeel"  VALUE="%lookAndFeel%">
<PARAM NAME="colorScheme"  VALUE="%colorScheme%">
<PARAM NAME="serverApp" VALUE="%serverApp%">
<PARAM NAME="logo" VALUE="%logo%">
<PARAM NAME="imageBase" VALUE="%imageBase%">
<PARAM NAME="formsMessageListener" VALUE="%formsMessageListener%">
<PARAM NAME="recordFileName" VALUE="%recordFileName%">
<PARAM NAME="EndUserMonitoringEnabled" VALUE="%EndUserMonitoringEnabled%">
<PARAM NAME="EndUserMonitoringURL" VALUE="%EndUserMonitoringURL%">
<PARAM NAME="heartbeat" VALUE="%heartbeat%">
<PARAM NAME="WebUtilLogging" VALUE="%WebUtilLogging%">
<PARAM NAME="WebUtilLoggingDetail" VALUE="%WebUtilLoggingDetail%">
<PARAM NAME="WebUtilErrorMode" VALUE="%WebUtilErrorMode%">
<PARAM NAME="WebUtilDispatchMonitorInterval" VALUE="%WebUtilDispatchMonitorInterval%">
<PARAM NAME="WebUtilTrustInternal" VALUE="%WebUtilTrustInternal%">
<PARAM NAME="WebUtilMaxTransferSize" VALUE="%WebUtilMaxTransferSize%">
<COMMENT>
<EMBED SRC="" PLUGINSPAGE="%jinit_download_page%"
        TYPE="%jinit_mimetype%"
        java_codebase="%codebase%"
        java_code="oracle.forms.engine.Main"
        java_archive="%archive_jini%,%webUtilArchive%"
        WIDTH="%Width%"
        HEIGHT="%Height%"
        HSPACE="0"
        VSPACE="0"

        serverURL="%serverURL%"
        networkRetries="%networkRetries%"
        serverArgs="%escapeParams% module=%form% userid=%userid% sso_userid=%sso_userid% sso_formsid=%sso_formsid% sso_subDN=%sso_subDN% sso_usrDN=%sso_usrDN% debug=%debug% host=%host% port=%port% %otherparams%"
        separateFrame="%separateFrame%"
        splashScreen="%splashScreen%"
        background="%background%"
        lookAndFeel="%lookAndFeel%"
        colorScheme="%colorScheme%"
        serverApp="%serverApp%"
        logo="%logo%"
        imageBase="%imageBase%"
        formsMessageListener="%formsMessageListener%"
        recordFileName="%recordFileName%"
        EndUserMonitoringEnabled="%EndUserMonitoringEnabled%"
        EndUserMonitoringURL="%EndUserMonitoringURL%"
        heartBeat="%heartBeat%"
        WebUtilLogging="%WebUtilLogging%"
        WebUtilLoggingDetail="%WebUtilLoggingDetail%"
        WebUtilErrormode="%WebUtilErrorMode%"
        WebUtilDispatchMonitorInterval="%WebUtilDispatchMonitorInterval%"
        WebUtilTrustInternal="%WebUtilTrustInternal%"
        WebUtilMaxTransferSize="%WebUtilMaxTransferSize%"
>
<NOEMBED>
</COMMENT>
</NOEMBED></EMBED>
</OBJECT>
<!-- Forms applet definition (end) -->

<!--
  <a href="javascript:CloseIt()">close</a>
-->

%HTMLafterForm%

</BODY>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
   //Control should not come here after loading the html page.
   if (autocenter)
   {
         windowX = ( window.screen.width-windowWidth ) / 2;
         windowY = (window.screen.height-windowHeight)/2;
         window.resizeTo(windowWidth,windowHeight);
         window.moveTo(windowX,windowY);
         window.resizeTo(300,300);
   }
-->
</SCRIPT>
</HTML>


ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial