Grow your CSS skills. Land your dream job.

Need help with “if” statements and combining javascript

  • # May 25, 2011 at 5:48 pm

    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.

    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.

    Any help would be appreciated.

    Thanks,

    Justin

    # May 27, 2011 at 5:21 am

    Wow, 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

    Thanks I’ll try this!

    # June 6, 2011 at 11:29 am

    HAHAH 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!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".