Javascript clear textarea

Hi… I’m pretty new to JS, so this might be a basic question
Can anyone tell me why is this code failing on a button action ?

Dim Id as String = TextArea1.ControlID me.ExecuteJavaScript("document.getElementById('"+id+"').value = '';")

thanks
R

What do you want to do?

Your button could better just set the textfield in Xojo to “” and than let Xojo send javaScript to browser.

ControlID is almost always the ID of some outter div wrapper. Check the DOM to see if the TextArea control has a div wrapper, and what the inner textarea id might be.

This is probably what you’re looking for (untested):

me.ExecuteJavaScript("document.getElementById('" + Me.ControlID + "_inner').value = '';")

It’s my first dive into Js… so…

@Christian Schmitz I am just experimenting and trying to learn. It’s not something I’m going to use in a real project
@Tim Parnell Got it. Hit F12 in chrome and saw the real ID of the textarea… Now I see what you mean. The suffix “_inner” is always added to the object inside the outter wrapper? Can I take this as a rule?

Thanks Anthony!

R

Pretty much, but always verify by inspecting in the browser.

[quote=448162:@Roman Varas]It’s my first dive into Js… so…

@Christian Schmitz I am just experimenting and trying to learn. It’s not something I’m going to use in a real project
@Tim Parnell Got it. Hit F12 in chrome and saw the real ID of the textarea… Now I see what you mean. The suffix “_inner” is always added to the object inside the outter wrapper? Can I take this as a rule?

Thanks Anthony!

R[/quote]

Greg O’Lone has regularly warned that the “_Inner” suffix may not always be used, and that it may change.