By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,905 Members | 879 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,905 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.