Dienstag, 1. November 2011

CGI 001: Combining Javascript and CGI

I wrote a minimal example involving Javascript and CGI. Javascript only
<html>
<script type="text/javascript">
    function helloworld()
    {
        document.write("Hello World.");
    }
</script>
<body>
    <input type="button" value="Hello World." onClick="helloworld()">
</body>
</html>
</pre>
Including CGI:
<html>
<script type="text/javascript">
    function helloworld()
    {
        return true;
    }
</script>
<body>
    <form action="./hello.cgi" onSubmit="return helloworld()">
        <input type="submit" value="Hello World.">
    </form>
</body>
</html>
The CGI part in Python
#!/usr/bin/python
print "Content-type: text/plain\n\n"
print "Hello World."
The Javascript function is nothing but a pseudo-function. It does nothing, but control of flow does go through it, otherwise the form is not submitted to the CGI.
Important to note is that the CGI script access the element name property, not the ID.

Keine Kommentare:

Kommentar veröffentlichen