help me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Asghar baig
    New Member
    • Jan 2007
    • 13

    help me

    i want to display an Array of length 5 on a alert box using loop what i have to do
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Assuming your array is named anArray:
    Code:
    for (i = 0; i < anArray.length; i++) alert(anArray[i]);
    If you want just one alert box with all values then declare a string variable which contains all values separated by spaces, newline or whatever you choose and then use an alert method to display the values.

    Comment

    • Asghar baig
      New Member
      • Jan 2007
      • 13

      #3
      I want to show it on only one alert box. the method u told it show many alert box.
      what u do for this code
      Code:
      <html><head>
      <script>
      ja=new Array(2);
      for(a=0;a<ja.length;a++){
      ja[a]=prompt("Enter Name"+a,"");
      }
      {
      alert("Names u enterd are\n1="+ja[0]+"\n2="+ja[1]);
      
      }</script>
      <title></title>
      </head>
      <body>
      </body>
      </html>

      Comment

      • Asghar baig
        New Member
        • Jan 2007
        • 13

        #4
        I want to show it on only one alert box. the method u told it show many alert box.
        what u do for this code
        Code:
        <html><head>
        <script>
        ja=new Array(2);
        for(a=0;a<ja.length;a++){
        ja[a]=prompt("Enter Name"+a,"");
        }
        {
        alert("Names u enterd are\n1="+ja[0]+"\n2="+ja[1]);
        
        }</script>
        <title></title>
        </head>
        <body>
        </body>
        </html>
        if i want to show value on only one box like my program using any loop[

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by Asghar baig
          I want to show it on only one alert box. the method u told it show many alert box.
          what u do for this code
          Code:
          <html><head>
          <script>
          ja=new Array(2);
          for(a=0;a<ja.length;a++){
          ja[a]=prompt("Enter Name"+a,"");
          }
          {
          alert("Names u enterd are\n1="+ja[0]+"\n2="+ja[1]);
          
          }</script>
          <title></title>
          </head>
          <body>
          </body>
          </html>
          if i want to show value on only one box like my program using any loop[
          You almost have it there if you want five values use as follows:
          Code:
          <script>
          ja=new Array(5);
          var str = "The names you entered are";
          for(a=0;a<ja.length;a++) {
          ja[a]=prompt("Enter Name"+a,"");
          str += "\n" + a +"=" + ja[a];
          }
          alert(str);
          </script>

          Comment

          • Asghar baig
            New Member
            • Jan 2007
            • 13

            #6
            thank u very much u have solved my problem

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by Asghar baig
              thank u very much u have solved my problem
              Glad to hear. Do you understand how it works and the differences with your code? If you can understand it, then next time you have a similar problem it will be easy to solve.

              Comment

              Working...