开发者

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

开发者 https://www.devze.com 2023-01-21 04:43 出处:网络
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 sim

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

精彩评论

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