Connecting Tech Pros Worldwide Help | Site Map

For loop containing HTML

Member
 
Join Date: Sep 2006
Posts: 68
#1: Feb 14 '08
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:

Expand|Select|Wrap|Line Numbers
  1. for($i = 1; $i <= $elements; $i++)
  2. {
  3.         print "Enter number $i: <br>";
  4.         print "<input type="text">";
  5. }
  6.  
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's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Feb 14 '08

re: For loop containing HTML


can't have double-quotes in a double-quoted string:
Expand|Select|Wrap|Line Numbers
  1. print "<input type="text">";
you have to escape them:

Expand|Select|Wrap|Line Numbers
  1. print "<input type=\"text\">";
better yet use the qq{} operator with your double-quoted strings:

Expand|Select|Wrap|Line Numbers
  1. print qq{<input type="text">};
or q{} since what you really have is a single-quoted construct:

Expand|Select|Wrap|Line Numbers
  1. print q{<input type="text">}; 
Member
 
Join Date: Sep 2006
Posts: 68
#3: Feb 14 '08

re: For loop containing HTML


Quote:

Originally Posted by KevinADC

can't have double-quotes in a double-quoted string:

Expand|Select|Wrap|Line Numbers
  1. print "<input type="text">";
you have to escape them:

Expand|Select|Wrap|Line Numbers
  1. print "<input type=\"text\">";
better yet use the qq{} operator with your double-quoted strings:

Expand|Select|Wrap|Line Numbers
  1. print qq{<input type="text">};
or q{} since what you really have is a single-quoted construct:

Expand|Select|Wrap|Line Numbers
  1. print q{<input type="text">}; 

It worked. Thank you!
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 900
#4: Feb 14 '08

re: For loop containing HTML


I was to slow......


--Kevin
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#5: Feb 14 '08

re: For loop containing HTML


Quote:

Originally Posted by eWish

I was to slow......


--Kevin


and you weren't fast enough either ;)
Reply