Solved

Javascript variable declaration

Posted on 2007-03-21
6
555 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:remcogoris
6 Comments
 
LVL 17

Expert Comment

by:NicksonKoh
Comment Utility
Hi,

Spelling error in function

function Minimizee() {

should be

function Minimize() {

Cheers
Nickson
0
 
LVL 17

Expert Comment

by:NicksonKoh
Comment Utility
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
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Do it like this:

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

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





0
 

Author Comment

by:remcogoris
Comment Utility
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>


0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
Comment Utility
I do not see where you actually put that field in a form

try changing
    window.document.frmCloseSetting.itflag.value...
to
    document.getElementById('itflag').value...

Michel
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now