Javascript Error: sub is null
-
One of the posts on my blog https://your-homeremedies.professorsopportunities.com/herbalremedies/ is getting this error when it appears on the home page, and the error prevents the script from functioning properly.
Error: TypeError: sub is null
Source File: https://your-homeremedies.professorsopportunities.com/include/index.js
Line: 269But the same post, when it appears as a single post, does not have the error, and the script works perfectly. The coding which uses the script is identical on the home page and the single post. I wrote this script 8 years ago, and have been using it all that time, and this error never occurred before.
Here is the HTML that fires the script:
<div class="question"> <p style="margin-top:30px;">Can you suggest natural herbs for depression?</p> <div style="display:inline;"> <button class="show" style="margin-left:142px;">Answer</button> <div class="box" style="position:absolute; left:-1px; top:-17px; visibility:hidden;"> <textarea readonly="readonly" id="area" rows="20" cols="150" style="width:342px; height:184px; margin-bottom:20px; background:#FFF;"> St. John’s wort is an herbal remedy that has been scientifically tested, and found to be effective in treating mild to moderate depression. It works just as well as antidepressant drugs, and does not have as many side effects. However, your doctor should definitely be consulted before taking St. John’s wort, since 1) it is not effective in treating major depression, and 2) it can interfere with certain prescription or OTC drugs. </textarea><br /> <span style="padding-left:132px;"> < <a href="#" class="hide">Close Box</a> > </span> </div> </div> </div>
The script itself is in another folder, and is called by javascript in the <head> section of the page: <script src=”https://your-homeremedies.professorsopportunities.com/include/index.js” type=”text/javascript”></script>. Here is the coding for the script:
var count = 0; function submitForm() { // Submit Form // Copyright 2006 Professional Website Design. // For other useful scripts and tutorials, see // https://www.professorscodingcorner.com/ // You may use or modify the script in any way // you want, but do not remove the first three // lines above. Although it's not required, I // would appreciate an email to let me know // the URL of the page where are using it. if (!document.getElementById) return false; var sub = document.getElementById("submit"); var form = document.getElementById("form"); var val = sub.getAttribute("value"); [ My Note: this is line #269 ] sub.onclick = function() { var email = document.getElementById("email"); if (email.value.length < 6) { alert("You forgot to enter your email address."); return false; } if (count == 0) { count++; var url = "https://your-homeremedies.professorsopportunities.com/cgi-bin/subscribe.cgi"; form.setAttribute("action",url); sub.setAttribute("value","Please Wait"); sub.style.backgroundColor = "#F00"; form.submit; return; } return false; } return true; }
I am completely at a loss. I can’t understand why the script works fine on the home page, but not on the single post – how can this be?
And – most important – how can I fix the bug?
—
Professor
- The topic ‘Javascript Error: sub is null’ is closed to new replies.