RE: including JavaScript array in Lisp web page with HTMLgen and Allegro Serve

"Greger Lindell" <[email protected]> Wed, 28 Sep 2005 14:31:55 +0200
Newsgroups gmane.lisp.allegro
Message-ID <[email protected]>
Hello,

Here is an example on how to do it in the simplest manner. We have developed
helper functions to do it nicer, but this should work . Normally we put
Javascript in a library and definitely avoid document.write, using DHTML is
much cleaner.

(let ((list '(45 46 47)))
  (flet ((last1 (list)
                (car (last list))))
    (with-output-to-string (out)
      (net.html.generator:html-stream out
                   (:html
                    (:head (:title "Creating and Accessing arrays")
                           ((:script "LANGUAGE" "JavaScript")
                            (:princ
                             (format nil
                                 "<!-- Hide
                numArray = new array(~{~a, ~}~a);
                document.write(\"[0]=\",numarray[0],\"<br>\");
                document.write(\"[1]=\",numarray[1],\"<br>\");
                document.write(\"[2]=\",numarray[2],\"<br>\");
                //End Hide-->"
                               (butlast list 1) 
                               (last1 list))))))))))

The ultimate improvement in cleanliness can be had by using XML to send the
data (45 46 47) to the browser and XSL (including JavaScript) to handle
layout and Browser functionality. You can see some examples of this done on
our web site. Check for example in (requires Internet Explorer)

http://www.inthan.com/aweb/crm01/Lisp/index.html

Look at the Table of Contents frame on the left (View Source) and you see we
send only data. All formatting (CSS-based) and functionality (lots of
Javascript) are done by the Browser.



Greger Lindell 

Inthan
Lisp Consulting
Tel: +32 (0)2 742 25 12 
GSM: +32(0)497 50 51 95

 





-----Original Message-----
From: markandeya [mailto:[email protected]] 
Sent: Wednesday, September 28, 2005 12:49
To: [email protected]
Subject: including JavaScript array in Lisp web page with HTMLgen and
Allegro Serve


Dear Lispers,
Help!!!
RE:  Web app with Alegro Serve, Publish a page including a Java Script 
array.
      I get a return list from a mysql select query. I want to send that 
info to the web page
      in such a way that it can be  manipulated in the browser. I want 
to  create an array
      in Java Script to hold the data and then i can call the array from 
events in the browser itself.
      1) How to include java script in an html page with HTMLgen and 
allegro serve??
      2) how to pass the list or an array into the java script array?
      
              Here is some code for a Java Script Array creation in a 
normal html page:
                <html>
                <h2>Creating and Accessing arrays</h2>
                <script language="Java Script">
                <!-- Hide
                numArray = new array(45,67,34);
                document.write("[0]=",numarray[0],"<br>");
                document.write("[1]=",numarray[1],"<br>");
                document.write("[2]=",numarray[2],"<br>");
                //End Hide-->
                </script>
                </html>
   how to put into the lisp code the hide and end hide, and how to 
include those semi-colons without emacs or other editors getting mixed 
up?             
                
    
        here is some basic code from Allegro's HTMLgen help: (defun
simple-table-c (count)  (with-open-file (p "test.html"
       :direction :output
       :if-exists :supersede)

   (html-stream p
       (:html
         (:head (:title "Test Table"))
         (:body
          ((:table border 2)
           (dotimes (i count)
             (html (:tr (:td (:princ i))
                        (:td (:princ (* i i))))))))))))         
                                    
                
       
        
        I have elegant code to take the Mysql list and put it into a 
lisp array but need to create, fill and pass a Java Script array.
        
        Thanks for your time and consideration, it is not only a 
tremendous help but a saving Grace for me. Peace and joy, Markandeya
        
        ps. Incase anyone wants to know why i want to pass an array, it 
is to display parent records in a table and when one clicks on a table 
row in the browser  the child row details are displayed in text boxes.