• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Populating a field based on a value of another field

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I am the greenest of green horns and I'm dipping my toes into the java waters for the first time, I'm hoping someone can help me with some basic code: I am working with 3 values: Quantum Block, Chargeable item & Internal Cost.
Essentially what I need is this

When:
short_description == "Quantum Block"
chargeable_item == true (it's a tick box, default to tick)
populate internal_cost (200.00) (default 200.00 in this field)

Any assistance you can provide would be greatly appreciated.
 
Marshal
Posts: 8856
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sean McGuire wrote:When:
short_description == "Quantum Block"
chargeable_item == true (it's a tick box, default to tick)
populate internal_cost (200.00) (default 200.00 in this field)


Hi Sean, couple of things to remember:

1. Never do not check String objects (or any other object) equality with "==". In this case you'd check if both reference variables refers to the same memory location, where object is stored.
Strings equality you suppose to check:

2. Example below is error-prone, so do not write code in that way:instead write:
If you'd do in your way, you could easily make a mistake, for example:
Can you notice mistake? What the output would be?

3. Variable names suppose to start with lower case, and the second word with an upper. So "changeable_item" you'd change to "changeableItem" and so on, "changeableItemCodeOneTwoThree..."
 
Sean McGuire
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:

Sean McGuire wrote:When:
short_description == "Quantum Block"
chargeable_item == true (it's a tick box, default to tick)
populate internal_cost (200.00) (default 200.00 in this field)


Hi Sean, couple of things to remember:

1. Never do not check String objects (or any other object) equality with "==". In this case you'd check if both reference variables refers to the same memory location, where object is stored.
Strings equality you suppose to check:

2. Example below is error-prone, so do not write code in that way:instead write:
If you'd do in your way, you could easily make a mistake, for example:
Can you notice mistake? What the output would be?

3. Variable names suppose to start with lower case, and the second word with an upper. So "changeable_item" you'd change to "changeableItem" and so on, "changeableItemCodeOneTwoThree..."



Firstly, thanks for taking the time to respond, I appreciated it.

In regards to your questions, boolean needs to be replaced by var and the output will error.

How do I go about populating the internal_cost variable with 200.00
 
Bartender
Posts: 689
17
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java does not use the keyword 'var'. Are you using Java or Javascript? Note these are two different and completely unrelated languages, despite the similar names.
 
Sean McGuire
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike. J. Thompson wrote:Java does not use the keyword 'var'. Are you using Java or Javascript? Note these are two different and completely unrelated languages, despite the similar names.



I incorrectly assumed they were one in the same, my bad, I meant Java script. Thanks for clarifying.
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're not the first person to make that mistake, and I dare say you won't be the last ;)
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Javascript is one of the implementations of the ECMAScript specification, and we have a forum where we usually discuss it. So I shall move this discussion thither.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now that we know that you are using JavaScript, please reply with your question clearly stated. At this point, I'm not sure what you are trying to accomplish.

Please be sure to UseCodeTags, proper indentation, and proper naming for variables.
 
We're all out of roofs. But we still have tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic