So there is a page with about 50 forms.
The first form is a search, so I skip that form.
The remaining 49, I care about.
Out of those 49, I am only looking for forms with the go value equal to renew.
I wrote the code in scratch pad and it works fine.
I paste it into Greasemonkey and I get "document.forms[i].go is undefined"
Here is my code:
var i=1 ;
var total = document.forms.length -1;
while (i<=total) {
var go_val = document.forms[i].go.value;
if(go_val == "renew"){
document.forms[i].setAttribute('target','_blank');
}
i++;
}
I have also tried this, to check if the go element exists and the form generates no errors, but does not run setattribute.
var i=0 ;
var total = document.forms.length -1;
while (i<=total) {
if(document.forms[i].go){
var go_val = document.forms[i].go.value;
if(go_val == "renew"){
document.forms[i].setAttribute('target','_blank');
}
}
i++;
}
Why does it work in scratch pad, but not in Greasemonkey?
I have found: “Pitfall #3: Named Forms and Form Elements” and figured it out…