Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

In HTML form adding new field

by srikrishnan (Beadle)
on May 10, 2012 at 05:13 UTC ( #969742=perlquestion: print w/replies, xml ) Need Help??
srikrishnan has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I am creating a HTML form using cgi perl

In this, I am trying to add new field by checking the previous field value, new field only display if the value of the previous field matches

I am trying something like below,

print '<tr><td>Position:</td><td><select name="hdtextstyle" onchange=" +ifrunon">'; print '<option value="newline">New Line</option>'; print '<option value="runon">Runon</option>'; print '</select>'; print '</td></tr>'; my $textstyle = param('hdtextstyle'); if (param(hdtextstyle) eq "Runon") { print '<tr><td>$textstyle</td></tr>'; }

please help me to solve this

Thanks in advance


Replies are listed 'Best First'.
Re: In HTML form adding new field
by marto (Bishop) on May 10, 2012 at 06:45 UTC

    Perl runs on the server side, JavaScript runs on the client side. I don't see a new form field being added in the example you've posted, I see the value of $textstyle being displayed if Runon is selected from, at least this seems to be what you're trying to do. You don't show what your JavaScript function ifrunon is doing.

    Without submitting the form you can't use Perl to check values of existing form fields and add new form fields, unless you use AJAX to do this, which seems overly complex when you could use plain old JavaScript to add (or show hidden) form fields depending on the values selected in other fields.

    Make your example work in a plain HTML file, using JavaScript to achieve this. Consider using a templating module such as HTML::Template to separate your HTML/JavaScript/CSS code from your Perl code. Ovid's CGI Course is worth reading if you are new to CGI.

Re: In HTML form adding new field
by Anonymous Monk on May 10, 2012 at 06:57 UTC
Re: In HTML form adding new field
by mendeepak (Scribe) on May 14, 2012 at 04:40 UTC

    hi srikrishnan
    i would like to give two different situations and imagine your are the end user of your site.
    1)(Allowing perl to add new fields as per your thinking) would you like if your sites page checks with server each time you change a value and take more than a minute to load
    2)(using client side script like JS/Ajax) would you like to get your site loading changes faster in less than seconds when ever you change the value

    which site will you take as an end user??
    i will choose second one
    then you should program it such a way that it benefits the end user.
    NB:"i am not jocking at PERL"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://969742]
Approved by davido
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2017-05-23 03:47 GMT
Find Nodes?
    Voting Booth?