Joerg has asked for the wisdom of the Perl Monks concerning the following question:

Sorry, my question was terribly disturbed. So I repeat it: Generating a HTML form from Perl I want to initialize an Input text field using the VALUE tag. The following works perfectly:  print "<INPUT Name='anyname' VALUE='abc def'>"; But using a variable that holds the text like here:  $v = "abc def";  print "<INPUT Name='anyname' VALUE=$v>"; the field gets only 'abc', the remainder after the blank is cut. Can anybody give an advice? Thanks, Joerg

Replies are listed 'Best First'.
Re: text cut at blanks
by Mushy (Scribe) on Aug 25, 2000 at 00:40 UTC
    Is it really or are you looking at what the displayed html is giving you? You probably just forgot the quotes there. The following
    <INPUT Name='anyname' VALUE=abc def>

    is creating a new tag def and setting VALUE to abc only

    print "<INPUT Name=\"anyname\" VALUE=\"$v\">";

    should fix it.

    --
    A much wittier reply came to mind immediately after I clicked the "Submit" button.

Re: text cut at blanks
by tenatious (Beadle) on Aug 25, 2000 at 05:15 UTC
    The problem is that to make valid html attributes, you need to have quotes around the attribute values. Although most modern browsers will let you get away with not quoting attribute values without a space, the html is not valid. If there is a space in the attribute value, usually browsers, will treat that as the beginning of another attribute.

    e.g. Your script says:

    print "<input name='anyname' value=abc def>";

    the browser sees

    <input name='anyname' value=abc (and some other attribute, def, that I don't recognize and which does not have a value, so I'll ignore it)>
    Experiment with various ways of quoting. I use qq(); for all of my html, except when I use the CGI.pm. e.g.
    $v = "abc def"; # $v only contains abc def not "abc def" $html = qq(<input name="anyname" value="$v">);

    or...

    $v = qq("abc def"); # $v now contains <i>"abc def"</i> $html = "<input name=\"anyname\" value=$v"; # you could also do it like this: $c = qq("abc def"); $html = qq(<input name="anyname" value=$c>);

    I leave it to you to discover which is easiest for you. Alternately, you could use the CGI.pm module and let it print the stuff for you.