• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Populating a field based on a value of another field

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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: 6846
470
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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: 64618
225
  • Mark post as helpful
  • send pies
  • 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: 67265
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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.
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!