javascript
hello,
I'm trying to make a very small script with greasemonkey to do some automatic things when a page loads. The first thing I need to do is to click on a link. I've done that. Then I need to select the 3rd element of a drop down list that appears a few moments (depending on the connection) after the link is pressed, without reloading the page (ajax or something like that). This I can't get to work, can you help me? The select has no id or class, but I can get its xpath value. There is only one select on the page. I've tried both setTimeOut and the DOMNodeInserted event with no effect. Code:
// ==UserScript== |
Surely the required selected index will be 2 ?
|
Yes you're right :)
but unfortunately it's just a typo, which means that it's not where the error comes from. I'm just a beginner so I don't really even know how to debug js (I'm just using notepad), but if I go to the error java console I can see "'func1' is not defined." |
Well define func1.
Here's a tip : window.func1 isn't the declaration you think it is. func1 = WHAT ? What is the type of the variable ? Where have you said what it is supposed to be ? Maybe var func1 = window.function() .... ? |
var func1 = window.function() { ... } doesn't work either.
It still says func1 is not defined. Please don't forget that this is not a regular js, it's greasemonkey, which adds some differences. I just picked this window.func1 = function() from the net (the book on greasemonkey). But since it's not working, I'm opened to any suggestions. Please help me. Thanks. |
I've tried quite a lot of things but none worked. Is there someone here who knows a bit about greasemonkey?
|
Can I get help on this please ?
I'm really a beginner but I would very much appreciate this to work for my personal use. |
Functions must be declared before they are used. Your script as above appears to call a function, func1() before any function is declared or described.
Code:
// the rest is supposed to wait until the select appears, and then select its second element, but this doesn't work: |
Why do you pass a string to setTimeout? The following works for me under Greasemonkey:
Code:
window.func1 = function() |
okay, thank you, it works now that I've not passed the string :).
Now my next problem: actually it just selected the correct element from the drop down menu, but nothing happened. The element is declared like this: <select onChange="f(this.options[selectedIndex].value)"> How could I fire that event ? I can't call f with location.assign( "javascript:" + "f(x)" + ";void(0)" ); because 'this' is not the same. Thanks. |
Can someone help me with that new situation please?
Thanks |
I don't understand the situation. Can you post an entire script and html page so I can reproduce the problem?
|
All times are GMT -5. The time now is 04:59 AM. |