By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,916 Members | 1,286 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,916 IT Pros & Developers. It's quick & easy.

null or not an object

P: 1
This has been drivind me crazy.

The problem is I get "null or not an object" for everything (I've tried each of these) I try to add to the code inside the castMyVote().

document.voteme.pollerOption.value
document.forms[0].pollerOption.value
this.parentNode.pollerOption.value
document.forms[0].elements['pollerOption'].value
document.getElementById('pollerOption'').value
document.getElementById('pollerOption'')

None of these work.

I'm a novice with javascript and I just can't figure it out. Please help.

Code:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <title></title>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  8. <script type="text/javascript">
  9. function selectphoto(pid) {
  10.   document.getElementById("pollerOption" + document.getElementById("pollerOption").value).style.border = "2px solid white";
  11.   document.getElementById("pollerOption" + pid).style.border = "2px solid #c33";
  12.   document.getElementById("pollerOption").value = pid;
  13. }
  14. function castMyVote(pollId,formObj)
  15. {    
  16.     var elements = formObj.elements['vote[' + pollId + ']'];
  17.     var optionId = false;
  18.     for(var no=0;no<elements.length;no++){
  19.         if(elements[no].checked)optionId = elements[no].value;
  20.     }
  21.     if(optionId){
  22.  
  23.         var ajaxIndex = ajaxObjects.length;
  24.         ajaxObjects[ajaxIndex] = new sack();
  25.         ajaxObjects[ajaxIndex].requestFile = serverSideFile + '?pollId=' + pollId + '&optionId=' + optionId;
  26.         prepareForPollResults(pollId);
  27.         ajaxObjects[ajaxIndex].onCompletion = function(){ showVoteResults(pollId,ajaxIndex); };
  28.         ajaxObjects[ajaxIndex].runAJAX();
  29.     }    
  30. }
  31. </script>
  32. </head>
  33. <body>
  34. <form name="voteme" action="<? echo $_SERVER['PHP_SELF']; ?>" onsubmit="return false" method="post">
  35.     <img src="http://www.google.com/intl/en_ALL/images/logo.gif" id="pollerOption1" style="border: 2px solid white; cursor: hand;" onclick="selectphoto('1')" /><br />
  36.     <img src="http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif" id="pollerOption2" style="border: 2px solid white; cursor: hand;" onclick="selectphoto('2')" /><br />
  37.     <input type="text" id="pollerOption" name="pollerOption" value="1" /><br />
  38.     <input type="submit" onclick="castMyVote(1, document.voteme.pollerOption.value);">
  39. </form>
  40. </body>
  41. </html>
thanks...
Jan 19 '08 #1
Share this Question
Share on Google+
1 Reply


100+
P: 210
Expand|Select|Wrap|Line Numbers
  1. onclick="castMyVote(1, document.voteme.pollerOption.value);"
This function expects a form object reference as its second parameter, but you are passing it the value of an element.
Jan 20 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.