|
-
Dec 4th, 2001, 08:43 AM
#1
Thread Starter
Frenzied Member
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;
}
}
}
-
Dec 4th, 2001, 08:48 AM
#2
Frenzied Member
make err2 public,
don't declare it in your function!
-
Dec 4th, 2001, 09:08 AM
#3
Thread Starter
Frenzied Member
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.
-
Dec 4th, 2001, 09:11 AM
#4
Frenzied Member
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!!
-
Dec 5th, 2001, 04:33 AM
#5
Thread Starter
Frenzied Member
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;
}
-
Dec 5th, 2001, 08:27 AM
#6
Frenzied Member
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
-
Dec 6th, 2001, 02:11 AM
#7
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|