Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 6th, 2008, 12:34 PM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default convert Excel formula to JavaScript

I'm trying to convert the following Excel formula to JavaScript:

=IF(C6>=500, C6*0.9,"")

I am trying to take the total of one column (C6) and if it is greater than 500, multiply it by .90 (and put that quantity in a new column).

I am creating a fillable pdf in Adobe Acrobat that will do calculations. It requires some JavaScript.

thank you
Reply With Quote
  #2 (permalink)  
Old March 6th, 2008, 01:03 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

The JavaScript equivalent is the ternary conditional operator:
expression ? when true : when false. So
Code:
var c6 = <value in cell C6>;
var result = (c6 >= 500) ? c6 * 0.9 : "";
--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old March 6th, 2008, 01:50 PM
Registered User
 
Join Date: Mar 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your quick response. when I put the following in, I am getting a syntax error.

var C6 = <value in cell C6>;
var result = (C6 >= 500) ? C6 * 0.9 : ""

if (C6>=500) {
    C6 * 0.9 : "";
  }

I am just learning JavaScript so it may be something very basic and simple. Thank you for your time.
Reply With Quote
  #4 (permalink)  
Old March 7th, 2008, 06:31 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

The items delimited by <> are meant to be replaced by your code, I can't tell how you get the initial value of cell C6 into a variable.
You don't need
Code:
if (C6>=500) {
    C6 * 0.9 : "";
  }

The variable 'result' holds the correct value, you need to put that into your column.

--

Joe (Microsoft MVP - XML)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel to Javascript formula assistance recei Javascript How-To 1 February 6th, 2007 10:25 AM
Excel calculations convert to pdf via javascript evetteogden Javascript How-To 0 May 31st, 2006 11:32 AM
Formula in Excel davekrunal46 Excel VBA 1 December 5th, 2005 06:51 AM
Formula to convert date format narooma.12 Crystal Reports 0 April 20th, 2005 04:54 PM
converting excel formula to javascript bRvO Javascript How-To 10 January 10th, 2005 12:41 PM



All times are GMT -4. The time now is 10:33 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.