Todd:
> <input type="text" maxlength="9" class="field" name="textMARS">
>
> The field is deep inside the page: nested inside a frame, then inside
> a form, and inside a cell in a table.
Jim:
> It's probably because 'textMARS' is not the id of the element but the
> name. Check out getElementsByName.
Jim is correct.
Also, if the field is within an iframe/frame then there's a chance
that you may not be able to get to it as easily as
document.getElementsByName() because IIRC document refers to the 'top'
document and the documents (frames) within this are defined separately
as contentDocument.
I strongly suggest doing some research of your own (I've not tested
this *at all*) but I think that this would be a good starting point to
doing what you seek to do:
// select the iframe element using your preferred method
// var iframe = document.getElementById("idOfTheFrame");
// var iframe = document.getElementsByTagName("frame")[0];
//(now that you have the first frame, either get the next nested frame
[[iframe.contentDocument.getElementsByTagName("frame")]] or seek out
the text field that you need)
// Select the Customer ID field
var customerIdField = iframe.contentDocument.getElementById('textMARS');
// Set the field's value
// NOTE: this is setting / storing login credentials in plaintext in
the script is *BAD*
// ((Also the same reasoning that many banks and secure sites eg Paypal use the
// autocomplete="off" attribute to prevent your browser from saving
login credentials))
customerIdField.value = '0123456789';
On 10/06/2010, John5342 <[email protected]> wrote:
> On Thu, Jun 10, 2010 at 01:21, Toddintr <[email protected]> wrote:
>> Thank you Kwah and Jim. I inspected the page using Firebug and here's
>> the element for the customer id field:
>>
>> <input type="text" maxlength="9" class="field" name="textMARS">
>>
>> The field is deep inside the page: nested inside a frame, then inside
>> a form, and inside a cell in a table.
>>
>> In my user script I have:
>>
>> document.getElementById('textMARS').focus();
>> document.getElementById('textMARS').value = "1234567";
>>
>> Unfortunately, I could not get it to work. I am able to print a
>> "hello world" message from the script so I know it is being invoked.
>> Could it be that I need to fully qualify the element because it's so
>> deep inside the page?
>
> It's probably because 'textMARS' is not the id of the element but the
> name. Check out getElementsByName. More details here:
> http://www.w3schools.com/jsref/dom_obj_document.asp
>
> --
> There are 10 kinds of people in the world: Those who understand binary
> and those who don't...
>
> --
> You received this message because you are subscribed to the Google Groups
> "greasemonkey-users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/greasemonkey-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.