开发者

Want to get all the text inputs from a form and put them in a JavaScript alert. Why isn't my code working?

My HTML contains a fieldset, six text input fields formatted in a table, and a submit button. The submit button includes the attribute o开发者_C百科nClick="check()" and it's worked with simpler alerts so I know that's not the problem. Here's my JavaScript:

var $ = function (id) { return document.getElementById(id); }

function check() {  
    var x = $("myForm");  
    var y;  
    for (var i=1; i < x.length; i++) {  
        y += (x.elements[i].value + "<br />;");}  
    alert("values: <br />" + y)  
    }

When I click the submit button, I don't get any alert at all. What should I do?


This is probably not the answer you're looking for.

If you're on Firefox, install the Firebug addon, open it up and see what errors you are getting.

If you're on Chrome, open up the Javascript console (Ctrl+Shift+J), and see what error your are getting.

Otherwise: choose your weapon :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜