[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Invoking CGI from Javascript - How ?
At 12:00 PM 2/7/96 CST, you wrote:
>Hi,
>Does anyone know how to invoke a cgi script from a Javascript function?
>
>When I click a button, I grab a bunch of form objects, build a query, and
>then want to pass it to a cgi on another server. Is such a feat possible?
>
>If so, and the cgi returns data, can Javascript "get" it and then process
>it?
You call the CGI script with the GET or POST method as part of the form.
This part is standard HTML.
If you wish to process the form contents before you send it to the CGI
script. you either add an onSubmit
event handler to the "Submit" button, or use the submit() method. I
personally prefer the latter, but either
will work. Either way your JavaScript code can look over the form results,
and if they pass muster, send
the form on. See http://gmccomb.com/valid.htm and valid1.htm for examples
of validating form input (the
valid1.htm example connects to a basic CGI script that echoes back the form
contents).
The CGI script returns data as text/html, and JavaScript lacks an input
stream method to read it. But, you
could fake sending back return values by using something like hidden fields
in a form. You don't even need to
have any visible form elements that show up in the browser: just a
<FORM></FORM> definition with hidden
text fields in it -- a hundred of 'em if you need that many. Your
JavaScript can peek inside these fields to see
what the server sent back. I imagine you could also use cookies for this,
but the hidden text approach is
probably easier.
-- Gordon