Solved

javascript error

Posted on 2013-06-17
6
216 Views
Last Modified: 2013-06-18
I have the following javascript on a web page.
It works fine with Internet Explorer, but on a Galaxy Tablet, it does nothing.  
Am I missing a character somewhere ?  I believe it may be something with the 'else' line (if I comment that line out, the rest works).

if (document.form1.AddItem7Amount.value > "0")
      {document.form1.AddItem7MarginPercent.value=+(parseFloat(document.form1.AddItem7AmountExt.value)-parseFloat(document.form1.AddItem7CostExt.value))/+parseFloat(document.form1.AddItem7AmountExt.value);
      document.form1.AddItem7MarginPercent.value=+(Math.round(document.form1.AddItem7MarginPercent.value*1000))/10};
    else document.form1.AddItem7MarginPercent.value = "0";
0
Comment
Question by:drelinger
  • 3
  • 2
6 Comments
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39254740
Try removing the semicolon preceding the else:
if (document.form1.AddItem7Amount.value > "0")
      {document.form1.AddItem7MarginPercent.value=+(parseFloat(document.form1.AddItem7AmountExt.value)-parseFloat(document.form1.AddItem7CostExt.value))/+parseFloat(document.form1.AddItem7AmountExt.value);
      document.form1.AddItem7MarginPercent.value=+(Math.round(document.form1.AddItem7MarginPercent.value*1000))/10} // no ; here!
    else document.form1.AddItem7MarginPercent.value = "0"; 

Open in new window

0
 
LVL 4

Assisted Solution

by:AnuTiji
AnuTiji earned 250 total points
ID: 39255361
Hi

Try adding curly brackets for the else

if (document.form1.AddItem7Amount.value > "0")
      {document.form1.AddItem7MarginPercent.value=+(parseFloat(document.form1.AddItem7AmountExt.value)-parseFloat(document.form1.AddItem7CostExt.value))/+parseFloat(document.form1.AddItem7AmountExt.value);
      document.form1.AddItem7MarginPercent.value=+(Math.round(document.form1.AddItem7MarginPercent.value*1000))/10};
    else { document.form1.AddItem7MarginPercent.value = "0";}
0
 

Author Comment

by:drelinger
ID: 39256005
when I comment that line out, the javascript run fine and calculates the fields.

When I leave that line in, the javascript doesn't run and none of the fields are calculated.

This fails on a Galaxy Tablet and also on the Blackberry browser.

The script runs fine either way on Internet Explorer.

Any reasons they would have an issue with that one line ? Just commenting out the 'else' line makes it work fine. strange.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:drelinger
ID: 39256020
...this is the element on the page. but I don't see any issue there.

<input name="AddItem7MarginPercent" type="text" class="mystyle31" id="AddItem7MarginPercent" size="2" maxlength="5" readonly="true">
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39256022
I tried it in FireFox and the problem is that the code is syntactically incorrect and doesn't compile/run at all. removing the semicolon before the else makes it work (as does commenting out the else but then it's different code).
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 250 total points
ID: 39256059
I'm not a 100% sure why IE compiles/runs this without a problem as opposed to Firefox (and others probably). Normally you don't use a semicolon to terminate statement blocks used in if/for etc, only for single statements.

Chrome clearly points out the problem:
capture
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question