Solved

javascript error

Posted on 2013-06-17
6
213 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:drelinger
Comment Utility
...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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now