473,397 Members | 1,974 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,397 software developers and data experts.

simple script inserted in websurvey software works in firefox but not in internet explorer

I am designing a web survey using surveymonkey.com and discovered I
could use javascript to modify their standard question formats much
the same as can be done in myspace.
I used this feature to insert a weight converter into my survey.
Unfortunately this script works fine in firefox v.2 but does not
cooperate with the surveymonkey software when used with internet
explorer v.6.
Can someone explain to me in simple terms why the script won't work
properly in both browsers? I paste the script below.

Many thanks,

Graham

<SCRIPT LANGUAGE="JavaScript">
<!-- all mult -->
function GetNumber1(form) {
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value);
if (isNaN(sNumber)) sNumber = 0;
sNumber = sNumber*pw3
sNumber = gesult(sNumber)
form.txtResult.value= sNumber}

<!-- all divide -->
function GetNumber1b(form) {
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value);
if (isNaN(sNumber)) sNumber = 0;
sNumber = sNumber/pw3
sNumber = gesult(sNumber)
form.txtResult.value= sNumber}

<!-- all mult -->
function GetNumber2(form) {
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value)
var ml3 = parseFloat(form.txtNumbe3.value)
var cNum2 = 0
cNum2 = pw3*ml3
sNumber = sNumber*cNum2
sNumber = gesult(sNumber)
form.txtResult.value= sNumber}

<!-- all divide -->
function GetNumber2b(form) {
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value)
var ml3 = parseFloat(form.txtNumbe3.value)
var cNum2 = 0
cNum2 = pw3*ml3
sNumber = sNumber/cNum2
sNumber = gesult(sNumber)
form.txtResult.value= sNumber}

function GetNumber22(form) {
var sAve = 0
var pw3 = parseFloat(stripBad(form.txtNumber.value));
var ml3 = parseFloat(stripBad(form.txtNumbe2.value));
if (isNaN(pw3)) pw3 = 0;
if (isNaN(ml3)) ml3 = 0;
sAve = (pw3*14) + ml3
sAve = gesult(sAve)
form.txtResult.value = sAve + " pounds" }

function GetNumber33(form) {
var sAve = 0
var pw3 = parseFloat(stripBad(form.txtNumber.value));
var md4 = 0
var lb4 = 0
md4 = pw3 % 14
lb4 = (pw3 - md4)/14
sAve = md4
sAve = gesult(sAve)
lb4 = comma(lb4)
form.txtResult.value = lb4 + " stone " + sAve + " pounds"
}
function GetNumber44(form) {
var sAve = 0
var pw3 = parseFloat(stripBad(form.txtNumber.value));
var ml3 = parseFloat(stripBad(form.txtNumbe2.value));
if (isNaN(pw3)) pw3 = 0;
if (isNaN(ml3)) ml3 = 0;
sAve = (pw3*14) + ml3
sAve = sAve * 0.45359237
sAve = gesult(sAve)
form.txtResult.value = sAve }
function stripBad(string) {
for (var i=0, output='', valid="eE-0123456789."; i<string.length; i
++)
if (valid.indexOf(string.charAt(i)) != -1)
output += string.charAt(i)
return output;
}

function gesult(ff){

if (Number.prototype.toFixed) {
ff = ff.toFixed(2);
ff = parseFloat(ff);
}
else {
var leftSide = Math.floor(ff);
var rightSide = ff - leftSide;
ff = leftSide + Math.round(rightSide *1e+14)/1e+14;
}

return comma(ff);
}

function comma(num) {
var n = Math.floor(num);
var myNum = num + "";
var myDec = ""

if (myNum.indexOf('.',0) -1){
myDec = myNum.substring(myNum.indexOf('.',0),myNum.length) ;
}

var arr=new Array('0'), i=0;
while (n>0)
{arr[i]=''+n%1000; n=Math.floor(n/1000); i++;}
arr=arr.reverse();
for (var i in arr) if (i>0)
while (arr[i].length<3) arr[i]='0'+arr[i];
return arr.join() + myDec;
}

</SCRIPT>

</HEAD>
<a name = "sptokg"><H2</H2></a>
<H5>*N.B. If you know your highest weight in stones and pounds, please
convert this to kg and enter the value in the box above</H5<p>
<FORM>
Enter stones: <INPUT TYPE="text" NAME="txtNumber" SIZE=3<B>and</B>
pounds: <INPUT TYPE="text" NAME="txtNumbe2" SIZE=3>
<INPUT TYPE="button" VALUE="Convert to Kg" class="b2t"
onclick="GetNumber44(this.form)" <INPUT TYPE="text"
NAME="txtResult" SIZE=3kg
<input type="reset" class="b3t">
</FORM>

<BR>

Jun 26 '07 #1
5 1686
On Jun 26, 1:17 pm, gray_slp <g.s.finlay...@gmail.comwrote:
I am designing a web survey using surveymonkey.com and discovered I
could use javascript to modify their standard question formats much
the same as can be done in myspace.
I used this feature to insert a weight converter into my survey.
Unfortunately this script works fine in firefox v.2 but does not
cooperate with the surveymonkey software when used with internet
explorer v.6.
Can someone explain to me in simple terms why the script won't work
properly in both browsers? I paste the script below.

Many thanks,

Graham

<SCRIPT LANGUAGE="JavaScript">
<!-- all mult -->
function GetNumber1(form) {
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value);
if (isNaN(sNumber)) sNumber = 0;
sNumber = sNumber*pw3
sNumber = gesult(sNumber)
form.txtResult.value= sNumber}

<!-- all divide -->
function GetNumber1b(form) {
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value);
if (isNaN(sNumber)) sNumber = 0;
sNumber = sNumber/pw3
sNumber = gesult(sNumber)
form.txtResult.value= sNumber}
<*snip*>

Because FF follows the ECMAScript specification
better.

But, just because you can, doesn't mean you
should, it just makes it more difficult to read.

<script type="text/javascript">

<!-- html comment hide script from older browsers

// all mult - javascript comment in code
// Of course as comments go, this one sucks
// because it doesn't really say anything
// useful
function GetNumber1(form)
{
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value);

if (isNaN(sNumber)) sNumber = 0;
sNumber = sNumber*pw3; // semicolons!
sNumber = gesult(sNumber);
form.txtResult.value= sNumber;
}

etc.

----
Geoff

Jun 26 '07 #2
Geoffrey Summerhayes said the following on 6/26/2007 3:45 PM:
On Jun 26, 1:17 pm, gray_slp <g.s.finlay...@gmail.comwrote:
>I am designing a web survey using surveymonkey.com and discovered I
could use javascript to modify their standard question formats much
the same as can be done in myspace.
I used this feature to insert a weight converter into my survey.
Unfortunately this script works fine in firefox v.2 but does not
cooperate with the surveymonkey software when used with internet
explorer v.6.
Can someone explain to me in simple terms why the script won't work
properly in both browsers? I paste the script below.

Many thanks,

Graham

<SCRIPT LANGUAGE="JavaScript">
<!-- all mult -->
function GetNumber1(form) {
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value);
if (isNaN(sNumber)) sNumber = 0;
sNumber = sNumber*pw3
sNumber = gesult(sNumber)
form.txtResult.value= sNumber}

<!-- all divide -->
function GetNumber1b(form) {
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value);
if (isNaN(sNumber)) sNumber = 0;
sNumber = sNumber/pw3
sNumber = gesult(sNumber)
form.txtResult.value= sNumber}

<*snip*>

Because FF follows the ECMAScript specification
better.
And what specification would that be?
But, just because you can, doesn't mean you
should, it just makes it more difficult to read.

<script type="text/javascript">

<!-- html comment hide script from older browsers
Which are obscenely outdated, unneeded and can cause problems in certain
scenarios.

The reason that IE doesn't "see" the script is it sees the improper
comment as a conditional comment and ignores what is between them.

<snip>
sNumber = sNumber*pw3; // semicolons!
Which are totally irrelevant in the posted code and are 100% optional
unless you want to place all your statements on one line.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 26 '07 #3
On Jun 26, 7:04 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
Geoffrey Summerhayes said the following on 6/26/2007 3:45 PM:
On Jun 26, 1:17 pm, gray_slp <g.s.finlay...@gmail.comwrote:
I am designing a web survey using surveymonkey.com and discovered I
could use javascript to modify their standard question formats much
the same as can be done in myspace.
I used this feature to insert a weight converter into my survey.
Unfortunately this script works fine in firefox v.2 but does not
cooperate with the surveymonkey software when used with internet
explorer v.6.
Can someone explain to me in simple terms why the script won't work
properly in both browsers? I paste the script below.
Many thanks,
Graham
<SCRIPT LANGUAGE="JavaScript">
<!-- all mult -->
function GetNumber1(form) {
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value);
if (isNaN(sNumber)) sNumber = 0;
sNumber = sNumber*pw3
sNumber = gesult(sNumber)
form.txtResult.value= sNumber}
<!-- all divide -->
function GetNumber1b(form) {
var sNumber = parseFloat(stripBad(form.txtNumber.value));
var pw3 = parseFloat(form.txtNumbe2.value);
if (isNaN(sNumber)) sNumber = 0;
sNumber = sNumber/pw3
sNumber = gesult(sNumber)
form.txtResult.value= sNumber}
<*snip*>
Because FF follows the ECMAScript specification
better.

And what specification would that be?
But, just because you can, doesn't mean you
should, it just makes it more difficult to read.
<script type="text/javascript">
<!-- html comment hide script from older browsers

Which are obscenely outdated, unneeded and can cause problems in certain
scenarios.
True. But <SCRIPT LANGUAGE="javascript"ain't
exactly state-of-the-art either.
The reason that IE doesn't "see" the script is it sees the improper
comment as a conditional comment and ignores what is between them.

<snip>
sNumber = sNumber*pw3; // semicolons!

Which are totally irrelevant in the posted code and are 100% optional
unless you want to place all your statements on one line.
Fair enough, I got rid of the comments right off,
and the script still didn't work, but it worked
after placing the semi's. Did it three times too.
Must have affected something else without realising
it.

FWIW, I prefer explicit semicolons, I find it
easier to parse and I don't have to worry about
the exceptional cases where the automatic
punctuation doesn't insert them.

---
Geoff

Jun 27 '07 #4
Geoffrey Summerhayes said the following on 6/26/2007 8:10 PM:
On Jun 26, 7:04 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>Geoffrey Summerhayes said the following on 6/26/2007 3:45 PM:
>>On Jun 26, 1:17 pm, gray_slp <g.s.finlay...@gmail.comwrote:
<snip>
>>But, just because you can, doesn't mean you
should, it just makes it more difficult to read.
<script type="text/javascript">
<!-- html comment hide script from older browsers
Which are obscenely outdated, unneeded and can cause problems in certain
scenarios.

True. But <SCRIPT LANGUAGE="javascript"ain't
exactly state-of-the-art either.
And type="text/javascript" is deprecated as well.
>The reason that IE doesn't "see" the script is it sees the improper
comment as a conditional comment and ignores what is between them.

<snip>
>> sNumber = sNumber*pw3; // semicolons!
Which are totally irrelevant in the posted code and are 100% optional
unless you want to place all your statements on one line.

Fair enough, I got rid of the comments right off,
and the script still didn't work, but it worked
after placing the semi's. Did it three times too.
Must have affected something else without realising
it.
Yes, as line ending semicolons don't mean a hill of beans to the parser.
FWIW, I prefer explicit semicolons, I find it
easier to parse and I don't have to worry about
the exceptional cases where the automatic
punctuation doesn't insert them.
Huh? Where the "automatic punctuation doesn't insert them"? Can you name
a parser that doesn't insert them? If you can, then it is ECMA broken as
semicolon insertion by the engine is specifically explained.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 27 '07 #5
On Jun 26, 8:30 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>
Huh? Where the "automatic punctuation doesn't insert them"? Can you name
a parser that doesn't insert them? If you can, then it is ECMA broken as
semicolon insertion by the engine is specifically explained.
Not what I meant. Any time the result is ambiguous,
that is to say, both inserting a semicolon and
not inserting one result in syntactically correct
statements, the parser is obligated not to insert a
semicolon. If the end result of not inserting the
semicolon results in an error during execution, tough.

Yes, it's reasonably rare and a mistake on the coder's
part, but it's not that obvious and simply putting in
the semicolons makes one less thing to watch for.

Also, if you end up using any of the other C syntax
based languages where missing semicolons is an error,
you'll develop the habit anyway.

Finally, if you need to reduce the size of the javascript,
it's pretty much guaranteed using a compacter will
give better results.

---
Geoff

Jun 27 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christoph | last post by:
The following script works fine on two Webservers in the internet, but it doesn't work on my local Webserver (Xitami). I also tried the IIS, with the same result - the script isn't forwarding me ...
2
by: Maik | last post by:
I Need a popup-killer script
6
by: goober | last post by:
Ladies & Gentlemen: I have built a form that client-side validates and posts data to a CRM beautifully in Internet Explorer (IE) 6. The problem comes in FireFox (FF) 1.5 when everything works...
9
by: DavidB | last post by:
Hi all I have a script that works perfectly in IE but not in FF. I am sure that the problem is easy to resolve, but I seem to be too dumb to figure it out. <html> <head> <script...
15
by: Lennart | last post by:
Hi folks, I have created an animated image gallery in dhtml. It works fine in Internet Explorer. In Firefox, it only works if I ommit the DOCTYPE tag. The page is valid xhtml-strict but with a...
1
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to...
1
by: Bjorndal | last post by:
Hey guys! I'm currently working on project, in which I need to animate a menu. It seems to work all right in Safari and Firefox, but Internet Explorer 7.0 makes the animation run slower, and I...
7
by: Larry | last post by:
The below script, I have been using for many years, stopped working in IE 7.0 all of a sudden. It works using NS and Firefox. Anyone know why this is? Did something change in IE 7.0 that may be...
7
by: sj071 | last post by:
I'm little more than a novice when it comes to javascript, and this particular problem has been driving me mad for the past few days... The Problem: I have a javascript file that uses...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.