简体   繁体   中英

JavaScript Uncaught Error in Chrome Console

my error is: Uncaught: TypeError: undefined is not a function .

I am trying to automatically fill a form without hitting submit (I can do that manually, as there is no class or ID on the submit button--then it will re-enter the next set of information after I hit it.) I am also unsure how to do the wait function properly. I have looked it up and tried a few various ways to no avail.

var qu = ["Do they offer whois privacy for domain registrations? free or at cost?"];
var an = ["Yes, so and so offers domain privacy options for domain registration."];
var q = document.getElementByName("question");
var a = document.getElementByName("answer");
var i = 0;
var delay = 2500;

do {
    q.value = qu[i];
    a.value = an[i];
    i++;
} while (i < qu.length)

Thanks!

getElementByName不是函数,而是getElementsByName() ,它不返回一个元素,它将返回您NodeList,因此您必须注意这一点。

There is a typo in there:

document.getElementsByName("question");
document.getElementsByName("answer");

see MDN docs

For the wait function you can use:

setTimeout( function(){
//do something
}, 500);

This will set a timeout (waiting time) for 500ms
see mdn for more info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM