Hi Sander,
To set an attribute in javascript you have to use the Mendix client API.
From the documentation:
mxobj.set("Name", "Henry");
This sets the attribute called “Name” with the value “Henry”.
To get a hold of the context object with the javascript snippet or html snippet you can use:
var mxobj = this._contextObj;
Here is a link to the mx7 and mx8 client api.
https://docs.mendix.com/apidocs-mxsdk/apidocs/client-api
Hope this helps!