Home › Forums › JavaScript › Need help with “if” statements and combining javascript
- This topic is empty.
-
AuthorPosts
-
May 25, 2011 at 5:48 pm #32855jcoderMember
I need help combining some javascript. The script is for displaying 3 images based on stock in the warehouse. On top of that, the stock is in ether “EA” each’s or in “TH” thousands, so the code has to times the TH by 1000. I have each part working independently. Need help combining them. In the javascript code you will see something like ##word## this is a token that pulls data from the database. Just think of it as a number. In the end result I wanted to be able to first figure out if it is in “EA” or in “TH” if in “TH” times by 1000 then run the second script below.
The first part is what determines to multiply “TH” by 1000.
if ("##iumr##" == "EA")
{
document.write(##IVULP##.toFixed(0)+" Rolls per Pack");
}
else if ("##iumr##" == "TH")
{
document.write(##IVULP##*1000+" Pieces per Pack" );
}
The second part is what tells it what image to use. In Stock, Partial Stock, Out of Stock. I need to combine the top code and the code below.
//var LQORDA = ##LQORDA##
//var LQORD = ##LQORD##checkVal(##Formula(@Sum(##LQORD## * 1000))##,##Formula(@Sum(##LQORDA## * 1000))##,##CLOSQTsell##)
//if (LQORD
// {
//document.write('([insert stock] available)');
// } else if (LQORD>LQORDA){
//document.write('([insert stock] available)');
//}Any help would be appreciated.
Thanks,
Justin
May 27, 2011 at 5:21 am #75202QbitMemberWow, this looks like code from hell. ;)
I realy tryed to figure out what you are tring to achive in your code, but have no idea. What framework causes such code? Maybe we can solve your problem on an abstract level.
If I got you right, you have two sripts A and B (different functions or files or what?). Normaly if you want the execution of B to be dependet of the execution of A you have store the decission from A in variable or a flag (or use the same if condition in B). You can now make your decission in B based on the flag or variable you have created in A.
var flag;
function A() {
if (unit == "EA") {
flag = "EA" /* you can also store a calculated value */
document.write("...");
}
else if (unit == "TH") {
flag = "TH"
document.write("..." );
}
}
function B() {
if (flag == "EA") {
/* do it for each */
document.write("...");
}
else if (flag == "TH") {
/* do it for thousands */
document.write("...");
}
}
Maybe this is a push in the right direction.
PS: Try using the code blocks in your posts. It makes the code much more readable.
June 6, 2011 at 11:26 am #74056jcoderMemberThanks I’ll try this!
June 6, 2011 at 11:29 am #74057jcoderMemberHAHAH it is crazy the system that I am using for web development. I have to use a lotus notes program that some guy developed and on top of that he uses his own programing language on top of HTML to build the website!
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.