Passing var between processing js and load different txt file in html by javascript

Passing var between processing js and load different txt file in html by javascript

I am not familiar with jQuery, so please explain more details to me.

1. I have a .pde file will detect user mouse click, and there are few object in it, if the user click on the first one, I will get '1' as output and so on. And I have create a var in javascript to store the output, but how can I change the var value in processingjs? (Under have the demo code, it will be more clear.)

2. How can I load different txt into a div in html depends on a var? When I done part one, and depends on the user click on different object, I want to load different txt in to the div("targetDiv" below). (e.g if object 2 is clicked, text2.txt will be loaded in div)


<!doctype html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script src="processing-1.3.6.js"></script>

<script type="text/javascript">

var outcome = 18;

</script>

<body>

<div id="targetDiv"></div>

<canvas data-processing-sources="testing.pde"></canvas>

</body>

</html>





and in the testing pde. ::


   


    void setup(){

    //sth happend

    }


    void draw(){

    //draw some object

     }


    void mousePressed(){

     //when user click on some obj

    //output the number of the object

    }