2 Replies Latest reply on Nov 17, 2011 3:37 PM by varkin80

    Display random image

    varkin80

      Hey all. Creating my first form in LiveCycle. Haven't a clue as to what I'm doing... maybe someone can help.

       

      I don't know javascript, so I usually just use trial and error until I figure it out... but I just can't get this to work.

      I have 20 images on my form (named ImageField#hg), invisible. I want to display a random image when I click a button.

       

      Here is the code I thought would work.... it's placed in the Click script section on a button.

       

      var one = "ImageField";

      var two = "hg";

      var rannumb = Math.floor(Math.random() * 19+1);

      var showg = one + rannumb + two;

      showg.presence = "visible";

       

      If I test the output in a text box, I get ImageField#hg (# being the random number), so why doesn't it actually execute the .presence action?

       

      Thank you.

      -James

        • 1. Re: Display random image
          varkin80 Level 1

          I've been trying to change my thinking on this and came up with different code, but it still won't work properly.

           

          This frist script actually does change the images to visible... however, it's processing the variable for some reason and both images become visible on click. I didn't know variable would do anything unless called.

           

          var one = ImageField1hg.presence = "visible";

          var two = ImageField2hg.presence = "visible";

          var rannumb = Math.floor(Math.random() * 19+1);

          var newnumb = WordNum(rannumb);

           

          testing.rawValue = newnumb; // test field to see output doesn't show anything

          newnumb;

           

          So I changed the script to the following and it does nothing.

           

          var one = ImageField1hg.presence;

          var two = ImageField2hg.presence;

          var rannumb = Math.floor(Math.random() * 19+1);

          var newnumb = WordNum(rannumb);

           

           

          testing.rawValue = newnumb; // test field to see output doesn't show anything

          newnumb = "visible";

           

          Back to the drawing board...

          • 2. Re: Display random image
            varkin80 Level 1

            Update:

             

            Well I figured out I had mixed Javascript & FormCalc code...

             

            I moved the random math function to a different field to use javascript.

            Now my WordNum function works.

             

            getran.execInitialize() // run script to make new random number

             

            var one = ImageField1hg.presence

            var two = ImageField2hg.presence

            var getnumber = getran.rawValue // get random number from field

            var newnumb = WordNum(getnumber) // change random number into text to match variables

             

            testing.rawValue = newnumb // conversion test does product correct text number

            newnumb = "visible" // does nothing.....

             

            I think I might have to go back to a ifelse statment... just seems like there should be a better way.