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='registration +email' /> <font color="red">Username: </font></font><input t +ype="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="pa +ssword" class="registrationfields" size="10" name="r_password"/> <font color="red">Password-Check: </font><input ty +pe="password" class="registrationfields" size="10" name="r_passwordch +eck"/> <br/> First Name: <input type="textfield" class="registr +ationfields" size="10" name="r_name"/><br/> Last Name: <input type="textfield" class="registra +tionfields" size="10" name="r_lastname"/><br/><br/> Email Validation Required within 24 Hours of Accou +nt Creation.<br/> <font color="red">Email: </font><input type="textf +ield" 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="registrati +onfields" size="10" name="r_country"/><br/> City: <input type="textfield" class="registrationf +ields" 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
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.

In reply to HTML::Template and Json with Jquery, cant get onkeyup data into my cgi. by tacogrande

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.