thehurricane
Joined: 03 Jul 2008 Posts: 1
|
Posted: Thu Jul 03, 2008 9:25 am Post subject: err msg: subscribeForm is null or not defined.....Why??? |
|
|
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: |
|