I cant seem to get this to work. I am trying to emulate this script http://www.shawngo.com/gafyd/index.html , checks the username with a database to see if its available.

I have tried the JSON + Jquery but i cant seem to get it to send the current value of the text field.

Here is what my HTML Template looks like.

My Header includes:

<script src="/java/jquery-1.3.2.js"></script>

---

The main template:

<form method="post" action="index.pl" enctype="application/x-www-form-urlencoded" name="reg">
                                        <input type='hidden' name='rm' 
value='registrationemail' />
<font color="red">Username: </font></font><input type="textfield" class="registrationfields" size="10" id="user" name="r_username" onkeyup="exported_func( ['user'], ['test']);">
                                        <TMPL_VAR NAME="TEST">
                                          <span id="ajax_spinner" style="display: 
none;">
                                                  <img 
src="../images/spinner.gif"/></span>
                                          <div id="display_user_details">
                                         </div>
                                         <div id="test">
                                         </div>
                                        <br/>
<font color="red">Password: </font><input type="password" class="registrationfields" size="10" name="r_password"/> <font color="red">Password-Check: </font><input type="password" class="registrationfields" size="10" name="r_passwordcheck"/>
                                        <br/>
First Name: <input type="textfield" class="registrationfields" size="10" name="r_name"/><br/> Last Name: <input type="textfield" class="registrationfields" size="10" name="r_lastname"/><br/><br/>
                                        
                                        Email Validation Required within 24 Hours of 
Account Creation.<br/>
<font color="red">Email: </font><input type="textfield" class="registrationfields" size="10" name="r_email"/> <font color="red">Email Check: </font><input type="textfield" class="registrationfields" size="10" name="r_emailcheck"/>
                                        <br/><br/>
                                        
Country: <input type="textfield" class="registrationfields" size="10" name="r_country"/><br/> City: <input type="textfield" class="registrationfields" size="10" name="r_city"/><br/>
                                        <br/>
                                        How did you find us?
                                        <br/>
<textarea rows=5 cols=20 class="registrationfields" name="r_find"></textarea><br/>
                                        <br/>
                                        <br/>
                                        <TMPL_VAR NAME="CAPTCHA">
                                        <br/>
                                        <input type="submit" value="Register"/>
                                        </form>

<script>

// show the spinner for AJAX requests
$("#ajax_spinner").ajaxStart(function(){
    $(this).show();
});
$("#ajax_spinner").ajaxStop(function(){
    $(this).hide();
});

$("#user").keyup(function(){

    $("div#display_user_details").html('');

 $.getJSON('?ajax=1', function(result){
        $("div#display_user_details").html(
           result.username

        );
   });
});

</script>


Here is my CGI STUFF

sub usernameCheck
{
        my ($query, $self) = @_;
        #my $enteredusername = $query->param('r_username');
        # check if its an AJAX submit
        if ( $query->param('ajax') ) {       
                my $usernamecheck = check_usernames($enteredusername);
                my $json = to_json($usernamecheck);
                print "Content-type: text/html\n\n";
                $self->header_add(-type => 'application/json');
                print $json;
                exit;
        }
}       
        
        
sub check_usernames
{
        my ($t) = @_;
    # pretend like we're doing some heavy task!
        #my $answer = checkdbforusername($t);
        sleep 0;
        my $userresult = {
        username => $t,
        };
        my $userresult2 = {
                username => $t,
                };
                if($answer == 1)
                {
                        return $userresult;
                }
        else
                {
                        return $userresult2;
                }
}

there is also a sub routine for checking the database, but right now i am just trying to get it to print the value.

I have also tried cgi::ajax, but i cant get it to work with cgi::app and html::template, this is a little over my head. Any help is appreciated.


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to