开发者

javascript elements is undefined

开发者 https://www.devze.com 2023-01-19 02:48 出处:网络
When I load vote.php on my web browser instead of index.php, I was able to vote and display user statistic. However I decided to implement the poll system by adding include(\'vote.php\') to index.php,

When I load vote.php on my web browser instead of index.php, I was able to vote and display user statistic. However I decided to implement the poll system by adding include('vote.php') to index.php, my document.forms[0] from vote.js can detect how many radio buttons in vote.php but I having problem getting this code working that appear to be "undefined" or not able to response, I did not modify any code all time:

JS code:

var objForm = objForm.e开发者_如何转开发lements['vote[' + pollId + ']'];

pollId is an integer type with value of '1' which is Poll question 1;

When I tried to trace using objForm.elements, it could show exact numbers of radio buttons I have implemented in HTML in the poll.

I need the solution to be "objForm.elements.vote[1]" before I could loop and detect which option did the user select.


You're not giving enough info to be sure, but my guess is that by using

var objForm = objForm.elements['vote[' + pollId + ']'];

in a loop, you are overwriting objForm for the next round. Try using a different variable name on the left hand side.

0

精彩评论

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