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

Dear Monks,

I'm looking for a way to have a button in my cgi form that will add another text input when clicked, similar to the attachments form in Yahoo Mail. This way the user can have exactly as many input fields as they need.

Any body help me in this.

Replies are listed 'Best First'.
Re: Add text box while click one button
by VinsWorldcom (Prior) on Mar 20, 2009 at 12:03 UTC

    Any code? Perhaps I don't understand the question fully, but if you want your HTML page to pop-up another text box when pushing a button on the HTML page, you should probably do that with some sort of HTML scripting (Javascript, etc...).

    If a Perl script is generating the HTML code, I think you'll still need to know the Javascript to write to the HTML to produce the desired result in the user's browser.

      Hi,

      I tried this through javascript in cgi page. But the code shows undefined in cgi page. The same works well in html page.

      The Java code is:

      function generateRow() {

      var d=document.getElementById("text");
      d.innerHTML+="

      <input type='text' name='food'>";
      }

      In the above the "getElementById" shows undefined.

      Any knows about this or any other method in CGI page.

      Regards, Balaji S

        This has nothing to do with Perl anymore. If document.getElementById('text') returns null, then there is no element with the id of 'text' in your HTML. If you're not already doing so, run Firefox and install the Firebug extension and spend some time getting to know it. I wouldn't think of doing any kind of Javascript or DOM debugging without it.