http://qs1969.pair.com?node_id=845867


in reply to Show / hide text field in cgi.pm application

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.

Replies are listed 'Best First'.
Re^2: Show / hide text field in cgi.pm application
by ady (Deacon) on Jun 22, 2010 at 17:39 UTC
    Thanks dsheroh,

    In hindsight I can see, that javascript is the way to implement client side dynamic functionality in this scenario.
    - I can take it from there :)

    Best regards, - allan