You should check out the Processing.js documentation, specifically the JavaScript Quick Start, specifically the Writing Documents that Combine Processing and JavaScript Code section.
There are three main ways to approach this: you can write Processing code that accesses an external JavaScript variable, or you could write JavaScript code that does something like call a setter function in your Processing code, or you could write JavaScript code directly in your Processing code.
Any of those approaches would work fine for what you're trying to do. If you still can't get it working, please post a MCVE of what you tried in a new question, and we'll go from there. Good luck.