Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: How to make a friendly UI

by thraxil (Prior)
on May 04, 2001 at 08:20 UTC ( #77869=note: print w/replies, xml ) Need Help??

in reply to How to make a friendly UI

"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 = " +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  //  
weblog       //

Replies are listed 'Best First'.
Re: Re: How to make a friendly UI
by Anonymous Monk on May 06, 2001 at 10:07 UTC
    Yes, all this is very much correct. I have had the dubious pleasure of doing a fair amount of this sort of thing via the hidden frame. A couple of important points to be on the look-out for:
    1. If you are expecting this to function as a "function" call, (i.e. returning a value, and/or halting execution of the calling process (javascript) untill returning) you are pretty much SOL. The loading of the cgi script in the hidden frame can be thought of as occuring in a different 'thread' if you will. In order to wait untill the return of the perl function (i.e., wait for the completion of the execution of the cgi, and download/render in your browser) you'd have to go into some horrible hokey javascript which gets vaguley reminiscent of programming in old-school basic with goto-line-numbers and the like... ugh, at the thought.
    2. in the javascript provided above, (which I understand is off-the-cuff... I merely point this out so that others avoid the potential pitfalls)
      <- document.location.href = newurl; -> parent.**hiddenJSframesNameHere**.document.location.href = newurl;
      or else you'll be reloading your own frame which is exactly what you wanted to avoid! and please, PLEASE use the javascript function escape(...) when constructing that get-string... like:
      var newurl = "" + escape(field) + "&value=" + escape(v +alue);
      (escape performs URI-escaping... for similar stuff in perl, look at URI::Escape)

    --a (hopefuly) helpful perl web-junky

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://77869]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2023-09-30 23:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found