Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


err msg: subscribeForm is null or not defined.....Why???



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
thehurricane



Joined: 03 Jul 2008
Posts: 1

PostPosted: Thu Jul 03, 2008 9:25 am    Post subject: err msg: subscribeForm is null or not defined.....Why??? Reply with quote

So, I made this script which would check if the email address entered is in the correct form. But I get an error message 'Cannot convert undefined or null to an object'.

Code:

var pageLoaded = 0;
var subscribeForm;

window.onload = function() {pageLoaded = 1;}


//This function waits for the elements to load then executes the get_txtbox function
function loader(i,f) {
  var j;
  if (document.getElementById && document.getElementById(i) != null)
  {
    j = document.getElementById(i);
    f(j);
  }
  else if (!pageLoaded) setTimeout('loader(\''+i+'\','+f+')',100);
}

//This function starts if an element with ID subscribeForm exists & the element is passed on to variable subscribeForm through an arguement
function get_txtBox(subscribeForm) {
//The startValidate function is called at the end of the get_txtbox function.
  var email_txtBox;
  function startValidate(email_txtBox) {
//I have the problem below. Browser says subscribeForm is undefined or null. This function does all the checking stuff.
    subscribeForm.onsubmit = function() {
      function echeck(str) {
        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)

        if (str.indexOf(at)==-1) {
          alert("Invalid E-mail ID")
          return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {
          alert("Invalid E-mail ID")
          return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {
          alert("Invalid E-mail ID")
          return false
        }

        if (str.indexOf(at,(lat+1))!=-1) {
          alert("Invalid E-mail ID")
          return false
        }

        if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {
          alert("Invalid E-mail ID")
          return false
        }

        if (str.indexOf(dot,(lat+2))==-1) {
          alert("Invalid E-mail ID")
          return false
        }
      
        if (str.indexOf(" ")!=-1){
          alert("Invalid E-mail ID")
          return false
        }

        return true               
      }

      var emailID=document.subscribeForm.email_txtBox

      if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email ID");
        emailID.focus();
        return false;
      }

      else if (echeck(emailID.value)==false) {
        emailID.focus();
        return false;
      }

      else {
        window.open('http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1969288', 'popupwindow', 'scrollbars=yes,width=550,height=520');
      }
    }
  }

  loader('email_txtBox',startValidate);
}

//Starts the function which checks for existence of elements (at the top)
loader('subscribeForm',get_txtBox);



And this is the HTML.
Code:

<form  method="post" name="subscribeForm" id="subscribeForm" action="http://www.feedburner.com/fb/a/emailverify"  target="popupwindow">
  <input name="email_txtBox" id="email_txtBox" type="text" value="" />
  <input name="send_btn" id="send_btn" type="submit" value="" />
</form>


I know I made the function all complex but I couldn't think of anything else.
And yeah, even though I get the error but still on submitting the form I get the alert boxes from subscribeForm.onsubmit. I'm totally confused.:confused:
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap