in reply to (OT) how to call cgi script from javascript?
Look into CGI::Ajax. There are several examples in the docs.