Q:

How to pass an encrypted value from a JAVA built HTML containing "onchange" to HTML

I am passing this from JAVA via AJAX to HTML:
json = json + "<input class='form-control mr-sm-2' type='date' name='awardDate' id='awardDate' value='" + youthMemberAward.getCaAwardedDate() + "' onchange='myFunction(this.value, " + youthMemberAward.getAwId() + ")' style='width: 160px;'/>";

However, I would like to encrypt youthMemberAward.getAwId() before passing it back:
byte[]   bytesEncoded = 
Base64.encodeBase64(youthMemberAward.getAwId().getBytes());//encoding part
String encoded_award_ID = new String(bytesEncoded);
json = json + "<input class='form-control mr-sm-2' type='date' name='awardDate' id='awardDate' value='" + youthMemberAward.getCaAwardedDate() + "' onchange='myFunction(this.value, " + encoded_award_ID + ")' style='width: 160px;'/>";

However, when I do this I get an error. When I inspect the page the error is:
Uncaught SyntaxError: Unexpected token )

The encrypted value being passed back is: Ng==
The reason for encrypting is that this value is the key I use to update the database when a change of date occurs. Therefore, I would like to prevent it being changed, by someone, before I update the database resulting in the wrong row being changed.

A:

You are passing a String into myFunction, therefore you need to wrap it with double quotations (")
"' onchange='myFunction(this.value, \"" + encoded_award_ID.replace("\"", "&quot;") + "\")' style='width: 160px;'/>";

and remember to escape double quotation in the process

