Reputation: 715
When using HtmlService (which uses Caja sanitization) can I get/set the value of a textbox (other controls)?
console.log('getting current value : ' + document.getElementById('z123').value);
where 'z123' is the id of unique textbox, the above code gives the error message:
Cannot read property 'value' of null
Certainly UiApp allowed this. So I'm not sure what is happening.
Upvotes: 0
Views: 219
Reputation: 2346
Use class instead id. In chrome devtools (Inspect element) you can see that Caja changes z123
(yourId) on z123-caja-guest-0___
(unlike the classes)
or with jquery you can use id..
$('#z123').val();
Upvotes: 2
Reputation: 43773
From within the Caja sandbox, getElementById
should work exactly as it usually does, as should .value
on form fields. If you're having trouble with this, please show your HTML as well as your JavaScript (preferably as a complete, short, example) so we can figure out what's going wrong.
On the other hand, if you're working from the browser console, then indeed that code would fail, as IDs are rewritten with a suffix (as already mentioned); from that context, document.getElementById('z123-caja-guest-0___')
should work. (There are ways to do this without knowing the format of the suffix, but they require already having the reference to the particular Caja sandbox.)
(I work on Caja.)
Upvotes: 1