Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Return problem (with function)
Old 06-20-2008, 07:05 PM Return problem (with function)
Junior Talker

Posts: 2
Name: Sven
Trades: 0
Hello

I'm busy with a new mini-project but I'm new with Javascript and AJAX.
I'm using a little bit of the Prototype Framework and the AJAX-object is a template from school.

But I've got a some problems with my formvalidation script. I created for every check (like: DublicateName, DublicateEmail, ValidEmail, ...) a function. Now I want to make a function that checks all these earlier functions.

File:
http://pastebin.parentnode.org/32203

Function example of the dublicate nickname
Code:
function CheckDublicateNickname() 
{
    var http = createREQ();
    var divReturn = $('return');
    http.onreadystatechange = function() {
        if(http.readyState == 4) {
            if (http.responseText == $('nickname2').value) {
                divReturn.innerHTML = "<p class='reg_error'>Nickname bezet!</p>";
                document.nicknameSrc.src = "img/ico.cross.png";
                $('nickname2').focus();
                return false;
            } else if (http.responseText == "No Result") {
                divReturn.innerHTML = "";
                document.nicknameSrc.src = "img/ico.accept.png";
                return true;
            } else if ($('nickname2').value == '') {
                divReturn.innerHTML = "<p class='reg_error'>Vul een nickname in!</p>";
                document.nicknameSrc.src = "img/ico.cross.png";
                $('nickname2').focus();
                return false;
            }
        }
    }
    http.open("POST", "php/modules/CheckDublicateNickname.php");
    http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    http.send("nickname=" + $('nickname2').value)
}
Overall function (this one need to check all the earlier functions)
Code:
function CheckRegistrationForm()
{
    var msg = "Volgende velden zijn niet of onjuist ingevuld: \n\n";
    var error = false;
    var nickname = $('nickname2').value;
    var email = $('email').value;
    var captcha = $('security_code').value;
    
    if (nickname == "") { 
        msg += "- Nickname \n"; 
        var error = true; 
    } 
    if (email == "") { 
        msg += "- E-mailadres \n"; 
        var error = true; 
    }
    if (captcha == "") {
        msg +="- Controle \n";
        var error = true;
    }
    if (error) { 
        alert(msg); return false;
    }
    if (CheckDublicateNickname() == true) {
        alert("test");
    }
}
Now when CheckDublicateNickname () is true, I want to store some data to a MySQL database with AJAX (this is not a problem). The problem is that my function: CheckDublicateNickname () doesn't give a true of false. At every if and else function is a return with true of false...

What is the solution?
I hope you can help.

Grtz,
Moby
Moby is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-20-2008, 07:06 PM Re: Return problem (with function)
Junior Talker

Posts: 2
Name: Sven
Trades: 0
When I add this: (red colored text)
Code:
function CheckDublicateNickname() 
{
    var http = createREQ();
    var divReturn = $('return');
    http.onreadystatechange = function() {
        if(http.readyState == 4) {
            if (http.responseText == $('nickname2').value) {
                divReturn.innerHTML = "<p class='reg_error'>Nickname bezet!</p>";
                document.nicknameSrc.src = "img/ico.cross.png";
                $('nickname2').focus();
                return false;
            } else if (http.responseText == "No Result") {
                divReturn.innerHTML = "";
                document.nicknameSrc.src = "img/ico.accept.png";
                return true;
            } else if ($('nickname2').value == '') {
                divReturn.innerHTML = "<p class='reg_error'>Vul een nickname in!</p>";
                document.nicknameSrc.src = "img/ico.cross.png";
                $('nickname2').focus();
                return false;
            }
        }
    }
    http.open("POST", "php/modules/CheckDublicateNickname.php");
    http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    http.send("nickname=" + $('nickname2').value)
    return true;
}
The function gives me the alert... But I want to have the returns insde the if(http.readyState == 4) { because I need the reaction (http.responseText) from my PHP file to validate and not from the whole functions...
Moby is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Return problem (with function)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.18508 seconds with 12 queries