homepage Welcome to WebmasterWorld Guest from 107.21.187.131
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
XML issue - can it be solved with JavaScript?
pcguru333




msg:1481323
 5:01 pm on Sep 30, 2004 (gmt 0)

I posted my issue in the XML programming forum but I haven't received an answer. I don't do much in JavaScript but I have experience with other languages. I have an issue where I am inserting values from an XML doc using XSL/Xpath, etc and I want to avoid issues where in some cases a divide by zero occurs. I would like to be able to trap those errors and instead of dividing simply display a result of zero.

Can this be done with JavaScript? Anyone with XML/XSLT and/or JavaScript experience is welcome.

Thanks
Dan

 

Bernard Marx




msg:1481324
 8:50 pm on Sep 30, 2004 (gmt 0)

In JS, there are 'class' properties:

Number.POSITIVE_INFINITY
Number.NEGATIVE_INFINITY

How you get these numbers into Javascript via XPath is another matter.


var n=3, k=0, q;

for(;k<4;k++){
q=3/(n-k);
if(q==Number.POSITIVE_INFINITY)
alert("division by zero")
else
alert(q)
}


pcguru333




msg:1481325
 10:29 pm on Sep 30, 2004 (gmt 0)

I have included snippet of code to see if someone can explain how I can use a JavaScript If statement.

In psuedocode:
If XMLValueA/XMLValueB = DivideByZero
Then Display '0'
Else Display XMLValueA/XMLValueB

Here is a snippet from my xsl doc:

<td style="text-align:right;">
<xsl:value-of select="format-number(Form101_A_Value div Form101_A_Number,'$#,###,###,##0')" />
</td>

Thanks
Dan

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved