Hello PerlMonks. I have a HTML file that has a form with different text input blocks (Add/Search/Delete)each with different submit buttons. There is a CGI script which takes all text box parameters from the HTML file. However, for each submit button, with "onclick" I want to pass a value(0,1,2 etc) to it so that I can have a switch case 1-Add, 2-Search etc in the CGI script for relevant Add/Search/Delete subroutines. Inside the html file I created a little javascript function as follows :

<script type="text/javascript"> var mysample = ''; function setval(varval) { mysample= varval; alert(mysample); } </script>
and posted this in the html for two submit buttons:
<input type="submit" value="Add Entry" onclick="setval(1)" /> <input type="submit" value="search" onclick="setval(2)" />
Also, I added a hidden input to pass the parameter to CGI :
<td align="left"><input type="hidden" name="mysample" size="15" maxlen +gth="50"></td>
However, on running the html file, it is not passing the mysample variable value to the CGI. Any ideas?

In reply to Pass variable values from HTML to CGI using "onclick" by newtoperl101

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.