Home:ALL Converter>jQuery Function and Javascript Functions Not Working Together

jQuery Function and Javascript Functions Not Working Together

Ask Time:2012-11-30T11:48:09         Author:MillerMedia

Json Formatter

I am trying to run a jQuery function with some other Javascript functions. I suppose I am not understanding the syntax correctly. I have a colorbox that opens on page load with a form in it. When the form is submitted I am trying to have a validation run first and then if successful run a jQuery function that closes the Colorbox and validates the parent window. This is where I'm at now (by the way, I've been all around the circle with this. I've been able to get the jQuery function to work, I've gotten the validation functions to work but I've never gotten them to work together. I apologize if I've gotten way off base but I think I've drifted away since I was trying some new things):

Just tried this:

window.echeck(str) = function {

    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                    
}

window.ValidateForm() = function{
var emailID=document.MailingList.emailaddress

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

$(document).ready(function() {  
    $('#submitbutton').live('click', function(e) {     
        ValidateForm();
        parent.$.fn.colorbox.close(); 
        parent.location.href = "/SearchResults.asp?Cat=1854";
    });
});

I didn't execute any of the functions.

When I remove ValidateForm(); from the jQuery and when I put the syntax of the javascript functions back to function ValidateForm(); instead of window.ValidateForm = function() the jQuery works but of course the other javascript functions do not.

Author:MillerMedia,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/13638729/jquery-function-and-javascript-functions-not-working-together
yy