5 Replies Latest reply on Jul 21, 2008 10:09 AM by c-fqgy

    Javascript question

    c-fqgy Level 1
      Hello,
      I was hoping I could show you a little Javascipt blurb that I'm trying to get to work. Its acutally not being used on the web, not even in Dreamweaver but in Adobe LiveCycles. Basically I have an invites for a BBQ that I want to send out but the BBQ is Potlock styled. Short of having everyone bringing desserts I want to randomize what the invites says to bring. Please note that I don't know very much about Javacript. I put this little bit together based upon other scripts I've found on the internet.

      Math.floor(Math.random()*3+1)

      meal = new Array(3);
      meal[1] = "a dessert";
      meal[2] = "a salad";
      meal[3] = "an appetizer";

      It sort of works... The math part does create a random pick between and including 1 and 3, but as soon as I put in what 1-3 equels (the array) it only picks "an appetizer".

      I don't mind figuring it out but if someone could steer me in the right direction that would be wonderful!!!!!
        • 1. Re: Javascript question
          Level 7
          The array items should start at 0:

          <script type="text/javascript">
          <!--
          meal = new Array(3);

          meal[0] = "a dessert";
          meal[1] = "a salad";
          meal[2] = "an appetizer";

          randnum = Math.floor ( Math.random() * meal.length );

          document.write(meal[randnum]);
          //-->
          </script>


          --
          Ken Ford
          Adobe Community Expert - Dreamweaver/ColdFusion
          Fordwebs, LLC
          http://www.fordwebs.com


          "c-fqgy" <webforumsuser@macromedia.com> wrote in message news:g62buo$foq$1@forums.macromedia.com...
          > Hello,
          > I was hoping I could show you a little Javascipt blurb that I'm trying to get
          > to work. Its acutally not being used on the web, not even in Dreamweaver but in
          > Adobe LiveCycles. Basically I have an invites for a BBQ that I want to send out
          > but the BBQ is Potlock styled. Short of having everyone bringing desserts I
          > want to randomize what the invites says to bring. Please note that I don't know
          > very much about Javacript. I put this little bit together based upon other
          > scripts I've found on the internet.
          >
          > Math.floor(Math.random()*3+1)
          >
          > meal = new Array(3);
          > meal[1] = "a dessert";
          > meal[2] = "a salad";
          > meal[3] = "an appetizer";
          >
          > It sort of works... The math part does create a random pick between and
          > including 1 and 3, but as soon as I put in what 1-3 equels (the array) it only
          > picks "an appetizer".
          >
          > I don't mind figuring it out but if someone could steer me in the right
          > direction that would be wonderful!!!!!
          >
          >
          • 2. Re: Javascript question
            c-fqgy Level 1
            Thank you for replying, unfortunately, it isn't bringing up anything at all with that script.
            • 3. Re: Javascript question
              Level 7
              If I put that script block between the <body> and </body> of a page it writes out one of the three?

              --
              Ken Ford
              Adobe Community Expert - Dreamweaver/ColdFusion
              Fordwebs, LLC
              http://www.fordwebs.com


              "c-fqgy" <webforumsuser@macromedia.com> wrote in message news:g62eh5$if8$1@forums.macromedia.com...
              > Thank you for replying, unfortunately, it isn't bringing up anything at all with that script.
              • 4. Re: Javascript question
                c-fqgy Level 1
                Just thought I'd say that I got the script to sort of work. I took the document.write(meal[randnum]); out and I'm getting random numbers now, just not the words. I'll keep playing!

                meal = new Array(3);

                meal[0] = "a dessert";
                meal[1] = "a salad";
                meal[2] = "an appetizer";

                randnum = Math.floor ( Math.random() * meal.length );
                • 5. Re: Javascript question
                  c-fqgy Level 1
                  I guess LiveCycle is just more picky than a browser? I have taken the script you have given me to the LiveCycles Forum, they are just not a fast about getting back to you as they are in this forum.

                  Thanks again for your help!!!