Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

javascript error

Posted on 2013-06-17
6
Medium Priority
?
221 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 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to implement server side field validation and display customized error messages to the client.
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

876 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