1

There's a site at work that I want to fill out with my name, email and phone number with either one click, or as soon as I navigate there.*

The site, in its most rudimentary form is this:

<html>
<body>

<table>
<TR>
<TD width="71"><BR><BR>Text1:&nbsp;</TD><TD colspan="5" width="608 <BR>**
  Text2<BR>
<input name="Comment" size="100" maxlength="200" value="na">
</TD>
</TR>
<TR>
</table>
</body>
</html>

I've tried approaches based on these two questions on this site:

But I just can't get anything to work. Here's the bookmarklet I have created:

javascript (function()%7Bdocument.getElementById("Comment").value%3D"Test111"%7D)()

but this gives an error of type "Uncaught TypeError: Cannot Set Property 'Value' of null"

I also created this bookmarklet:

javascript:(function()%7Bdocument.getElementByTagName("Comment")[0].value%3D"moo"%7D)()

which gives me an error of type "Uncaught TypeError: undefined is not a function"

I'm lost in the woods; I have experience coding but mostly data parsing and analysis in python or FORTRAN (eep). HTML and the various related scripting languages are really interesting to me, but I just don't understand them well enough to tackle this problem.

*If there's a way for me to submit a form of this type without actually navigating to the site, that would be great as well.

Community
  • 1
  • 1
rajan
  • 435
  • 3
  • 9
  • Just to make sure I'm being clear, I'm trying to use the bookmarklet to autofill the "Comment" field with a text string of my choosing. – rajan Feb 13 '15 at 05:42
  • 1
    Neither has that element an _id_, nor is its _tag_ name `comment` … – CBroe Feb 13 '15 at 10:09
  • @CBroe thanks for comment, so I'm referring to the input incorrectly it appears. The thing is that if I make this an "id" so that it says "id="Comment"" then I can autofill it using getElementByID("Comment").value..... I just don't know why I can't use the TagName or ID if name="Comment" – rajan Feb 14 '15 at 02:08
  • 1
    _“I just don't know why I can't use the TagName or ID if name="Comment"”_ – because `name="Comment"` _is_ neither the id or the _tag_ name of the element …? `` – that would be an element with the id `bar` and the tag name `foo`; yours is neither of those. You might want to read http://stackoverflow.com/questions/16664205/what-is-the-difference-between-getelementsbytagname-and-getelementsbyname-in-jav – CBroe Feb 14 '15 at 12:23

1 Answers1

1

Using getElementsByTagName works in this way:

document.getElementsByName('Comment')[0].value='Moo'

Essentially I had 3 different ways of calling the element and a bunch of ways of structuring the syntax for these three ways. Only 1 combination of these possibilities actually worked and I found some information on them here:

Mozilla getElementsByName documentation

Thanks to CBroe for pointing me in the right direction.

rajan
  • 435
  • 3
  • 9