Solved

javascript error

Posted on 2013-06-17
6
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses
Course of the Month11 days, 13 hours left to enroll

623 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