"Is it possible to call a perl function from onChange? or is it possible to call a perl function from within a javascript function or is there a completely different way to do this that I havn't thought of?"

you "call" a cgi script by sending an HTTP request. so you can't really call a specific perl function directly from javascript. the best you can do is put whatever functionality you wanted from the function into its own perl script and send requests for that.

normally, if your browser sends an HTTP request, it will load the page it gets as a response into the browser, replacing the current page. you can get around this by having your perl script send back non-parsed headers. (see the documentation for the CGI module for info on how to do that). the other option is the hidden frame trick mentioned earlier.

on the javascript end of things, you'd want to have it change the url of the current document to the url of the nph perl script, plus as many fields as necessary passed as GET variables.

ie, you'd probably have something similar to:

<input type="text" name="foo" onblur="updateField("foo",this.value)" />

where the javascript function updateField has been defined as something like:

function updateField(field,value) { var newurl = "http://www.example.com/update-single-field-nph.pl?fiel +d=" + field + "&value=" + value; document.location.href = newurl; }

this is all off the top of my head, so there are probably some things i forgot. obviously, you would also need to pass along something akin to the primary key for the record so the script knows which one to update. plus you'd have to be careful to url encode everything you pass in the url, etc, etc.

all in all, the benefit probably isn't worth the work it would take to get it all to work.

anders pearson // digital samurai
personal/pgp  // http://www.columbia.edu/~anders/  
weblog       // http://thraxil.dhs.org

In reply to Re: How to make a friendly UI by thraxil
in thread How to make a friendly UI by daveh71

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.