I need to select a form via native javascript (not jQuery) and prevent the form submission (preventDefault).
The trick is that the form does not have a name or id, and cannot be assigned one.
My HTML:
<div id="search">
<form method="get">
<input type="text" name="post"/>
<input type="submit" value="Post">
</form>
</div>
So far, I have tried to use document.forms[0]
and document.getElementsByTagName("form")[0]
to select the form, but the value returned is undefined.
Another possible solution is to overload the functionality of the submit button, but I did not have success with that either.