I'm a novice programmer trying to automate an extremely redundant task at work.
I want to insert some form elements and a text button, but I can't find the correct way to do it.
Here's what I have:
//function stuff
var searchyText = document.createElement("TEXTAREA");
var searchyDiv = document.createElement("P");
searchyDiv.innerHTML="<p><a href='#' onClick='searchyTimeGo()'>Click to Search</a></p>";
document.forms[0] ... ?
// document.insertBefore(searchyDiv, document.forms[0]);
// document.insertBefore(searchyText, searchyDiv);
The question mark is where I got lost, and the comments at the bottom are the failed results of my attempts so far.
I just can't get the text to show up on the page. I've looked at a few video tutorials and realized that I know exactly squat about nodes. There's only one form on the page.
I've gotten "undefined" to write itself in a few times -- when I tried to concatenate the raw HTML to the form[0].innerHTML
.
I felt dirty and ugly for even trying that, and it still didn't work.
I'm aware that the onClick
method I've included above will probably fail, but I know how to fix that.
Thank you for your time!