I have a weebly site with the 'note to seller' option enabled. There's no way to edit this field, so I'm trying to add a custom message to the textarea with javascript and I'm running into a bit of trouble. The textarea has no id, only a name attribute.
HTML code:
document.getElementsByName("order_notes")[0].innerHTML="PUT YOUR PERSONALIZED MESSAGE HERE";
var standard_message = document.getElementsByName("order_notes")[0].innerHTML;
var x = document.getElementsByName("order_notes")[0];
x.addEventListener("focus", myFocusFunction, true);
x.addEventListener("blur", myBlurFunction, true);
function myFocusFunction() {
if (document.getElementsByName("order_notes")[0].innerHTML == standard_message)
document.getElementsByName("order_notes")[0].innerHTML="";
}
function myBlurFunction() {
if (document.getElementsByName("order_notes")[0].innerHTML == "")
document.getElementsByName("order_notes")[0].innerHTML=standard_message;
}
<div id="wsite-com-checkout-notes">
<form>
<h2 class="wsite-panel-title">Note to Seller (Optional)</h2>
<div class="wsite-form-field">
<div class="wsite-form-input-container">
<textarea class="wsite-form-input wsite-input" name="order_notes"></textarea>
</div>
</div>
</form>
</div>
When viewing the checkout page (where the field is), I immediately see this error in the console: Uncaught TypeError: Cannot set property 'innerHTML' of undefined, but if I type in the code in the console again it works perfectly. The code is executed right before the closing 'body' tag, so the textarea is already created by the time the code kicks in. I also tried running the code with window.onload but I still get the same error.
I tried using jQuery first but for some reason Weebly won't recognize the function, even though the library is loaded and there are other functions using jQuery already.
Any ideas what could be causing this? All help is appreciated!