开发者

Quick way to alert the values of all input elements in a form?

I have a form with about 10+ input elements in it... For testing, I'd like to alert all their values... Is there a quicker way than this:

var f = document.getElementById('myForm').getElementsByTagName("INPUT");
alert(f[0].name + ' ' + f[0].value);
alert(f[1].name + ' ' + f[1].value);
alert(开发者_如何学Pythonf[2].name + ' ' + f[2].value);
... and so on...


You'll want to use a for loop for that.

var f = document.getElementById('myForm').getElementsByTagName("INPUT");

for (var i = 0; i < f.length; i++)
    alert(f[i].name + ' ' + f[i].value);

If you are just testing/debugging things, I'd recommend using your browser's console. Using Chrome or Firefox + Firebug you can call the console.log method and then drill down into your object. This tends to be a bit easier to manage in my opinion.


The smart way to do this is to instead install an extension similar to the Web Developer add-on, then use Forms -> View Form Information to see the values of all inputs.

Google Chrome version is here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜