Results 1 to 7 of 7

Thread: Value from a js-file in a function

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Question Value from a js-file in a function

    I have a function where I use a js-file. In this JS-file there is a variable named err2, which I want to use in the function. How do I get this value?
    Code:
    function tempValues() {
    		var luftf1 = document.cond.luftf.value;
    		var flow1 = parent.frames[1].navform.flow.value;
    		var retur1 = parent.frames[1].navform.retur.value;
    		var jordt1 = parent.frames[1].navform.jordt.value;
    		var afst1 = parent.frames[1].navform.afst.value;
    		var jordd1 = parent.frames[1].navform.jordd.value;
    			
    		temp_values();
    			
    			var err1 = 0;
    			if (document.cond.system.value == "true" || document.cond.rortype.value == "false") {
    				alert("Beregning af kondens kan kun udføres på enkeltrør til frie systemer.");
    				window.parent.frames("right").location = "about:";
    				err1 = 1;
    			}
    			
    			var err3 = 0;
    			if (isNaN(luftf1) || isNaN(flow1) || isNaN(retur1) || isNaN(jordt1) || isNaN(afst1) || isNaN(jordd1)) {
    				alert("Indtast venligst en numerisk værdi.");
    				err3 = 1;
    			}
    			if ((err2 == 0) && (err1 == 0) && (err3 == 0)) {
    				return true;
    			}
    			else {
    				window.parent.frames("right").location = "about:";
    				return false;
    			}	
    }
    The JS-file goes here
    Code:
    function temp_values() {
    var err2 = 0;
    		/* Værdier for St. 37 */
    		if (parent.frames[1].navform.mat.options[mat].text == "St. 37.0 BW") {
    			if (flow1*1 > 140 || flow1*1 < -60) {
    				alert("Temperaturområdet for St. 37 er -60°C - 140°C.");
    			window.parent.frames("right").location = "about:";
    			err2 = 1;
    			}
    		}
    		/* Værdier for St. 35 */
    		if (parent.frames[1].navform.mat.options[mat].text == "St. 35.8 I") {
    			if (flow1*1 > 140 || flow1*1 < -60) {
    				alert("Temperaturområdet for St. 35 er -60°C - 140°C.");
    			window.parent.frames("right").location = "about:";
    			err2 = 1;
    			}
    		}
    			
    		/* Værdier for Pex */
    		if (parent.frames[1].navform.mat.options[mat].text == "LR-Pex") {
    			if (flow1*1 > 95 || flow1*1 < -60) {
    				alert("Temperaturområdet for LR-Pex er -60°C - 95°C.");
    			window.parent.frames("right").location = "about:";
    			err2 = 1;
    			}
    		}
    			
    		/* Værdier for Cu-Flex */
    		if (parent.frames[1].navform.mat.options[mat].text == "Cu-Flex") {
    			if (flow1*1 > 130 || flow1*1 < -60) {
    				alert("Temperaturområdet for Cu-Flex er -60°C - 130°C.");
    			window.parent.frames("right").location = "about:";
    			err2 = 1;
    			}
    		}
    			
    		/* Værdier for Steel-Flex */
    		if (parent.frames[1].navform.mat.options[mat].text == "Steel-Flex") {
    			if (flow1*1 > 130 || flow1*1 < -60) {
    				alert("Temperaturområdet for Steel-Flex 35 er -60°C - 130°C.");
    			window.parent.frames("right").location = "about:";
    			err2 = 1;
    			}
    		}
    			
    		/* Værdier for AISI */
    		if (parent.frames[1].navform.mat.options[mat].text == "AISI 316L") {
    			if (flow1*1 > 140 || flow1*1 < -60) {
    				alert("Temperaturområdet for AISI 316L er -60°C - 140°C.");
    			window.parent.frames("right").location = "about:";
    			err2 = 1;
    			}
    		}
    	}

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    make err2 public,
    don't declare it in your function!

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Csn I do this by setting

    public err2 = 0;

    or...?

    I have tried not declare err2, but then an error occurs saying err2 is undefined.

  4. #4
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    nope, you can't use public or private,
    it depends where you declare them!
    just make it the first thing

    var err2;

    tempValues();

    that you will be able to use it in your function, but don't
    re-declare it in your function!!

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Sorry to disturb you, but something is going wrong.
    I have now made a simple function with the variable err5.
    If I set err5 = 15 in the function, and use this in the original function, it says that err5 is undefined. Maybe you can see, what's wrong?

    Code:
    function tester() {
    var err5;
    test();
    if (err5==15){
    alert("Defined");
    }
    else
    {
    alert("Undefined");
    }
    }
    
    ...
    function test() {
    	err5 = 15;
    	
    }

  6. #6
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    you still declare inside the function

    Code:
    var err5; //OUTSIDE YOUR FUNCTION
    
    function tester() {
    test();
    if (err5==15){
    alert("Defined");
    }
    else
    {
    alert("Undefined");
    }
    }
    
    ...
    function test() {
    	err5 = 15;
    	
    }
    now this will work

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Great, thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width