CGI (and CGI.pm) code runs solely on the server, so it has no interaction with what the user sees unless new data or a new document is fetched from the server.
All client-side dynamic functionality has to be implemented in javascript, since that's the only way to run code natively in the user's browser. (Yes, there are plugins to run other languages in browsers, but javascript is pretty much the only thing you can count on having there. Maybe also flash, if you're only targeting desktops/laptops and not mobile devices.)
The specific property I tend to use for dynamic control of visibility is the CSS "display" property:
<input type=text name=field1 onChange='document.getElementById("peekab
+oo").style.display = "block"'>
<div id='peekaboo' style='display: hidden'>
<input type=text name=field2>
</div>
This should (untested code) cause the peekaboo div (and its contained field2 text field) to appear when text is entered into field1. From there, you should be able to work out the javascript logic to have it flip peekaboo.style.display back and forth between hidden and block based on the content of field1 using whatever criteria you have in mind.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|