473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

javascript malfunction in IE and firefox

I have written a javascript code but it works only in IE and chrome and not in firefox. I mean, when I click the button to call the function, in firefox I see no action (!)

On the other hand the background image is displayed only in firefox and not in IE.

What is the source of these inconsistencies?
May 21 '09 #1
18 2682
acoder
16,027 Expert Mod 8TB
Browsers don't all behave the same, but it usually helps to code to standards where possible. Post your code, otherwise we'd have no idea what might be causing the problem.
May 21 '09 #2
I thought it is a general problem. Here is the code. Thanks,

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Untitled Document</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
  6. <style type="text/css">
  7. <!--
  8. .style2 {font-size: 18px}
  9. body {
  10.     background-image: url(background.jpg);
  11. }
  12. -->
  13. </style>
  14. </head>
  15.  
  16. <body>
  17. <script language='javascript' type='text/javascript'>
  18. function calc() {
  19.  <!-- main code -->
  20.  
  21. </script>
  22.  
  23.  
  24. <form id="form1" name="form1" method="post" action="">
  25.   <p>
  26.     <label>
  27.  
  28.     <div align="left">
  29.       <fieldset>
  30.       <legend><span class="style2">Environment</span></legend>
  31.       <div align="left">
  32.         <input type="radio" name="Environment" value="1" id="Environment_0" >
  33.         <span class="style2">Residential</span> </div>
  34.       <div align="left"><input type="radio" name="Environment" value="2" id="Environment_1" >
  35.         <span class="style2">Official</span></div>
  36.       <div align="left"><input type="radio" name="Environment" value="3" id="Environment_2" >
  37.         <span class="style2">Industrial</span></div>
  38. </fieldset>
  39.       <p align="left" class="style2">Please insert the following information:</p>
  40.  
  41. <label>
  42.   <div align="center" class="style2">Velocity (m/s)&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
  43.     <select name="V" id="V">
  44.       <option selected >Very low</option>
  45.       <option>Low</option>
  46.       <option>Medium</option>
  47.       <option>High</option>
  48.       <option>Very high</option>
  49.     </select>
  50. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Garment Insulation (clo)
  51. <select name="C" id="C">
  52.   <option selected="selected">Low</option>
  53.   <option>Medium</option>
  54.   <option>High</option>
  55. </select>
  56.   </div>
  57.   <span class="style2">
  58.   </label>
  59.   <label>
  60.   </span>
  61. <div align="center" class="style2">Relative humidity (%)
  62.    <input name="R" type="text" id="R" size="8" >
  63. &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Metabolic Heat Generation (met)
  64. <select name="M" id="M">
  65.   <option selected="selected">Low</option>
  66.   <option>Medium</option>
  67.   <option>High</option>
  68. </select>
  69. </div>
  70. </label>
  71. <label></label>
  72.   <label>
  73.  
  74. <div align="left">
  75.   <p align="center">
  76.     <input name="C2" type="button" id="C2" value="Calculate" onclick="calc()" />
  77.   </p>
  78. </div>
  79. </label>
  80.   <label>
  81.   <div align="left">
  82.     <p align="center">Temperature (C)
  83.       <input name="T" type="text" id="tem" size="10" maxlength="5" >
  84.     </p>
  85. </div>
  86.   </label>
  87. <label>
  88.  
  89. <div align="left">
  90.   <p align="center">
  91.     <input name="E" type="submit" id="E" onclick="window.close()" value="Exit" >
  92.   </p>
  93. </div>
  94. </label>
  95. <p>&nbsp;</p>
  96. <p> </p>
  97. </body>
  98. </html>
May 21 '09 #3
acoder
16,027 Expert Mod 8TB
If it's the calc() function that's not working, I'll need to see that. Can you post that using code tags please.
May 21 '09 #4
It is also lengthy. thanks,
Expand|Select|Wrap|Line Numbers
  1.     var k = 0;
  2.     if ( form1.Environment[0].checked ) {
  3.         k = 1;
  4.     }
  5.     else if ( form1.Environment[1].checked )
  6.         k = 2;
  7.     else if ( form1.Environment[2].checked )
  8.         k = 3;
  9.  
  10.     var n = 0;
  11.  
  12.     <!-- reading velocity combo box -->
  13.     var zz = form1.V.selectedIndex;
  14.     switch ( zz ) {
  15.         case 0:
  16.             var v = 0.1;
  17.             break;
  18.         case 1:
  19.             var v = 0.2;
  20.             break;
  21.         case 2:
  22.             var v = 0.3;
  23.             break;
  24.         case 3:
  25.             var v = 0.5;
  26.             break;
  27.         case 4:
  28.             var v = 1.5;
  29.             break;
  30.     }
  31.  
  32.     var i = form1.M.selectedIndex;
  33.     var j = form1.C.selectedIndex;
  34.  
  35.     switch ( k ) {
  36.         case 1:
  37.             switch ( i ) {
  38.                 case 0:
  39.                     var met = 0.7;
  40.                     break;
  41.                 case 1:
  42.                     var met = 1.2;
  43.                     break;
  44.                 case 2:
  45.                     var met = 2.4;
  46.                     break;
  47.                 case 0:
  48.                     var met = 0.7;
  49.                     break;
  50.             }
  51.             switch ( j ) {
  52.                 case 0:
  53.                     var clo = 0.38;
  54.                     break;
  55.                 case 1:
  56.                     var clo = 0.5;
  57.                     break;
  58.                 case 2:
  59.                     var clo = 0.9;
  60.                     break;
  61.             }
  62.             break;
  63.         case 2:
  64.             switch ( i ) {
  65.                 case 0:
  66.                     var met = 1.0;
  67.                     break;
  68.                 case 1:
  69.                     var met = 1.4;
  70.                     break;
  71.                 case 2:
  72.                     var met = 2;
  73.                     break;
  74.             }
  75.             switch ( j ) {
  76.                 case 0:
  77.                     var clo = 0.7;
  78.                     break;
  79.                 case 1:
  80.                     var clo = 1.0;
  81.                     break;
  82.                 case 2:
  83.                     var clo = 2;
  84.                     break;
  85.             }
  86.             break;
  87.         case 3:
  88.             switch ( i ) {
  89.                 case 0:
  90.                     var met = 2.0;
  91.                     break;
  92.                 case 1:
  93.                     var met = 3.0;
  94.                     break;
  95.                 case 2:
  96.                     alert ( "wrong" );
  97.                     break;
  98.             }
  99.             switch ( j ) {
  100.                 case 0:
  101.                     var clo = 0.7;
  102.                     break;
  103.                 case 1:
  104.                     var clo = 1.4;
  105.                     break;
  106.                 case 2:
  107.                     var clo = 2.5;
  108.                     break;
  109.             }
  110.             break;
  111.     }
  112.  
  113.     var hc = 12.1 * Math.pow(v, 0.5);
  114.     var Rcl = clo * 0.155;
  115.     var M = met * 58.1;
  116.     var W = 0.05 * M;
  117.     if ( clo > 0.5 )
  118.            var fcl = 1.05 + 0.1 * clo;
  119.     else
  120.            var fcl = 1.0 + 0.2 * clo;
  121.  
  122.     var hum = parseFloat(form1.R.value);
  123.     var Tcl1 = -10.0;
  124.     var Tcl2 = 40.0;
  125.     var T = 5.0;
  126.     var TemOpt = 5.0;
  127.     var dif = 100;
  128.  
  129.     for ( z = 1; z <= 1000; z++ ) {
  130.         var Pt = Math.exp(16.6536 - 4030.183 / (T + 235.0));
  131.         var Pa = hum * 10 * Pt;
  132.         var Tcl = root(Tcl1, Tcl2, M, W, fcl, hc, Rcl, T);
  133.         var l = (M - W)
  134.         var PMV = (0.303 * Math.exp(-0.036 * M) + 0.028) * l;
  135.         if (Math.abs(Math.abs(PMV) - 0.5) < dif) {
  136.                var TemOpt = T;
  137.                dif = Math.abs(Math.abs(PMV) - 0.5);
  138.         }
  139.            T = T + 0.03;
  140.  
  141.     }
  142.     form1.tem.value = TemOpt;
  143. }
  144.  
  145. function root( Tcl1, Tcl2, M, W, fcl, hc, Rcl, T ) {
  146.     while (Math.abs(f(M, W, fcl, hc, Rcl, Tcl1, T) >= 0.001 )) {
  147.           var Tcl3 = Tcl2 - f(M, W, fcl, hc, Rcl, Tcl2, T) - f(M, W, fcl, hc, Rcl, Tcl1, T);
  148.  
  149.     if (f(M, W, fcl, hc, Rcl, Tcl3, T) * f(M, W, fcl, hc, Rcl, Tcl1, T) < 0.0)
  150.         var Tcl1 = Tcl3;
  151.       else
  152.         var Tcl2 = Tcl3;
  153.     }
  154.     return Tcl3;
  155. }
  156.  
  157. function f(M, W, fcl, hc, Rcl, Tcl, T) {
  158.     var x = 35.7 - 0.028 * (M - W) - Rcl * (0.0000000396 * fcl * (Math.pow(Tcl + 273, 4) - Math.pow(T + 273, 4)) + fcl * hc * (Tcl - T)) - Tcl;
  159.     return x;
  160. }
  161.  
May 21 '09 #5
acoder
16,027 Expert Mod 8TB
I've not checked the rest of it, but the first problem I notice is the reference to form1 in the global scope. That is incorrect. Either use
Expand|Select|Wrap|Line Numbers
  1. document.forms["form1"]
  2. // or
  3. document.form1
  4. // or
  5. document.getElementById("form1")
May 21 '09 #6
Thanks, That worked for clac(), but the "exit" button reset the form. It does not show a window to confirm for close.
The original Exit function is:
Expand|Select|Wrap|Line Numbers
  1. <input name="E" type="submit" id="E" onclick="window.close()" value="Exit" >
With your cue, it has to be document.form1.window.close(), but that does not work either.

Also what about the problem of backgound image. It is shown in firefox but not in IE (!)
May 21 '09 #7
acoder
16,027 Expert Mod 8TB
document.form1.window.close() would be incorrect. window.close() only works on windows opened using JavaScript. If this is in the original browser window, it won't work. Use it in a pop-up window opened using window.open().
May 21 '09 #8
Sorry, did not understand what you said... :(
May 21 '09 #9
acoder
16,027 Expert Mod 8TB
When you open the browser and visit a web page, that is the browser you opened. Now, on that web page, when you click a button, it opens a new window. This window has been opened using JavaScript, so can be closed using JavaScript (window.close()) whereas the previous browser window cannot.
May 21 '09 #10
yes. In this site, I saw a solution for that. There should be a manual close function and in that, first the window has to be opened and then call the close function. An interesting thing is that "dom.allow_scripts_to_close_windows" in "about:config" (firefox) has to be 'true'. Thanks for the reference.


How about the background image? it works in firefox but not in IE (!)
May 21 '09 #11
acoder
16,027 Expert Mod 8TB
Yes, I've seen that hack, but it doesn't work in all browsers (for obvious reasons).

As for the background image, it's a CSS problem, so ask in the HTML/CSS forum.
May 21 '09 #12
Is it possible to change a value in about:config (firefox) automatically? I mean when the page is loaded, with a javascript function I change "dom.allow_scripts_to_close_windows". If it is not possible, then I have to write a notice at the end of the page and alert the user that "exit" function may not work in firefox
May 25 '09 #13
Dormilich
8,658 Expert Mod 8TB
I doubt that. it would be too much a security issue. (would you like a website changing your browser settings?)
May 25 '09 #14
acoder
16,027 Expert Mod 8TB
Why do you even need the Exit function? It'd make sense if you'd opened a window, but in the original browser window, there's no need to close it.
May 25 '09 #15
gits
5,390 Expert Mod 4TB
@mahmoodn
it would work but not silently ... the user has to confirm that change and so you cannot rely on that ... here is a link for the usage of the mozilla PrivilegeManager ...

kind regards
May 25 '09 #16
After my last post, I thought it is not suitable to change someones settings in an embedded manner.

I think there is no need for close button. The tab has a close button for itself.

Thanks,
May 25 '09 #17
acoder
16,027 Expert Mod 8TB
Yes, that's more like it. No need for tricks and hacks for something which doesn't give any/much benefit.
May 26 '09 #18
Ciary
247 Expert 100+
for a comparison of window.close in all (latest) browsers.
  • opera 9.6 will allow it. i dont know if that can be changed.
  • safari and chrome wont whatsoever. as with opera i dont know if it can be changed.
  • firefox3 wont allow it but will if changed in config
  • IE7 will show a warning messagebox and will ask if its ok to continue
  • for IE8 i have no idea but i guess the same as IE7

but as said, window.close is useless
May 26 '09 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Howard Kaikow | last post by:
Yesterday, I decided to try Firefox. I've encountered a behavior that is either a bug in Firefox or a bug in my Javascript code. I'll try to explain the problem, hoping that this newsgroup can...
2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
13
by: John Smith | last post by:
I am using IE 6.0 from http://www.javaworld.com/javaworld/jw-07-1996/jw-07-javascript-p2.html I gather that "If you need to test a number of command lines, you can reduce the keystrokes by...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
4
by: David McNerney | last post by:
Would anyone be able to tell me why I get an error in FireFox 1.5.0.1 for MacOSX when I type some text and hit Enter in the following form: <html> <body> <form action="http://example.com"...
4
by: lmarceglia | last post by:
Hi, I have this website that doesn't work in Firefox 1.5: www.pianetaluca.com The HTML source is: <TITLE>PianetaLuca</TITLE> </HEAD>
11
by: minnesotti | last post by:
Hi there, I subscribed to a photographic pictures-hosting website which is heavy on JavaScript. My preferred latest browser Mozilla Firefox does not work with it -- no pictures are displayed and...
8
by: Matt Kruse | last post by:
http://news.zdnet.com/2100-1009_22-6121608.html Hackers claim zero-day flaw in Firefox 09 / 30 / 06 | By Joris Evers SAN DIEGO--The open-source Firefox Web browser is critically flawed in...
16
by: Eric | last post by:
I have a user of a web application written in Java/JSP that is unable to login to the site simply because certain links on the page do not run when they are clicked. Other popups using Javascript...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.