Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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
[Corion]: Meh. My bank removed (part of) their CSV download facilities. Now I will either have to implement a full scraper or automate the download using the HBCI interface instead (or just get a new account elsewhere...)
[Corion]: On the upside, I spend a lot of time thinking this weekend about how to actually implement rate limiting for futures, and if things work out, maybe even loading a configuration from an external file makes sense
[Corion]: I've also found some interesting invariants that I have to think/write about more. A simple rate limiter will never change the order of the input, while a limiter that allows for parallel execution will change the order. But my API currently allows for bo

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2017-10-23 08:19 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (277 votes). Check out past polls.