Insert Template

in Script development
Subscribe to Insert Template 5 posts, 2 voices



MonkeyMargie Scriptwright
ieWindows

I am new to JavaScript. I have a Description field on a form. I need some GreaseMonkey code to check if the field is empty, and if so, insert a template into the field. If it's not empty, I want to leave it alone. Is there code available to do this? Thank you.

 
Jefferson Scher Scriptwright
FirefoxWindows

Generally speaking, you should be able to do this. Note that you need a way to identify the particular form field, which depends on your particular page.

if (myFormField.value.length == 0){
  myFormField.value = "some big long chunk of text";
}

 
MonkeyMargie Scriptwright
ieWindows

Thanks for your help. What I really want to do is -- See if this field is empty:

<textarea></textarea>

If it is, I want to insert some text in it:

<textarea>Monkey Text here
</textarea>

 
MonkeyMargie Scriptwright
ieWindows

I think part of it got cut off. It should be:

"

<textarea>Monkey Text here
</textarea>
"

 
Jefferson Scher Scriptwright
FirefoxWindows

Does this work?

if (myTextarea.textLength == 0){
 myTextarea.textContent = "some big long chunk of text";
}

Note: there isn't enough information in your posts to set myTextarea.