For loop containing HTML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JWest46088
    New Member
    • Sep 2006
    • 74

    For loop containing HTML

    I am trying to write a form loop that displays a text box however many times the user wants. For example, if the user enters 4, 4 text boxes will show up.

    Here is the code I have now for the for loop:

    Code:
    for($i = 1; $i <= $elements; $i++)
    {
            print "Enter number $i: <br>";
            print "<input type="text">";
    }
    I get this error:

    Bareword found where operator expected at assignment4.pl line 127, near ""(displays a textbox here)"" syntax error at assignment4.pl line 127, near ""(displays a textbox here)

    Thanks in advance!
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    can't have double-quotes in a double-quoted string:
    Code:
    print "<input type="text">";
    you have to escape them:

    Code:
    print "<input type=\"text\">";
    better yet use the qq{} operator with your double-quoted strings:

    Code:
    print qq{<input type="text">};
    or q{} since what you really have is a single-quoted construct:

    Code:
    print q{<input type="text">};

    Comment

    • JWest46088
      New Member
      • Sep 2006
      • 74

      #3
      Originally posted by KevinADC
      can't have double-quotes in a double-quoted string:
      Code:
      print "<input type="text">";
      you have to escape them:

      Code:
      print "<input type=\"text\">";
      better yet use the qq{} operator with your double-quoted strings:

      Code:
      print qq{<input type="text">};
      or q{} since what you really have is a single-quoted construct:

      Code:
      print q{<input type="text">};
      It worked. Thank you!

      Comment

      • eWish
        Recognized Expert Contributor
        • Jul 2007
        • 973

        #4
        I was to slow......


        --Kevin
        Last edited by eWish; Feb 14 '08, 10:29 PM. Reason: To slow....

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Originally posted by eWish
          I was to slow......


          --Kevin

          and you weren't fast enough either ;)

          Comment

          Working...