Solved

javascript error

Posted on 2013-06-17
6
215 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JQuery JavaScripot loop though RadioButtonList 4 25
PHP Form Calculate Total Price 10 42
Jquery 10 20
Not allowed to load local recource. 4 12
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

809 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