hi,
my full code then you understand easily

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

 <script src="md5.js" type="text/javascript"></script>// this script
used in encoding format



<title>Captcha </title>

 <script src="md5.js" type="text/javascript"></script>
<script type="text/javascript">

var XMLHttpArray = [
        function() {return new XMLHttpRequest()},
        function() {return new ActiveXObject("Msxml2.XMLHTTP")},
        function() {return new ActiveXObject("Msxml2.XMLHTTP")},
        function() {return new ActiveXObject("Microsoft.XMLHTTP")}
];
function createXMLHTTPObject(){
        var xmlhttp = false;
        for(var i=0; i<XMLHttpArray.length; i++){
                try{
                        xmlhttp = XMLHttpArray[i]();
                }catch(e){
                        continue;
                }
                break;
        }
        return xmlhttp;
}
function AjaxRequest(url,method){
        var req = createXMLHTTPObject();
        req.onreadystatechange= function(){


             if (req.readyState == 4){
       if (req.status == 200){
       var resarray = req.responseText.split("<#>");
    document.getElementById('question').innerHTML= resarray[0];
    document.getElementById('ans1').value = resarray[1];
    document.getElementById('ans2').value = resarray[2];
       }
      else if (req.status == 404){
         alert("Request URL does not exist");
         }
       else {
         alert("Error: status code is " + req.status);

       }
        }
        }
        req.open(method,url,true);
        //req.setRequestHeader('User-Agent', 'My XMLHTTP Agent');
        req.setRequestHeader("Content-Type", "text/html");
        req.send(null);
}
function AjaxResponse(req){
        var respXML=req.responseXML;
        if(!respXML) return;
        var respVAL=respXML.getElementsByTagName('family')[0]
.getAttribute('result');
        document.getElementById("status").innerHTML += respVAL;
}
function ClearResponse(){
        mdiv=document.getElementById("status");
        mdiv.innerHTML = "";
}
function MakeRequest(){

        AjaxRequest(action="fn.php?id=1",method="get");
}


  function handleKeyPress(e){
var key=e.keyCode || e.which;
if (key==13){

check();
//form.submit();
//return false;


}
}





function check()
{
var chk = document.getElementById('hash').value ;
alert(chk);
var chk1 = document.getElementById('ans1').value;
var chk2 =document.getElementById('ans2').value;
if((chk == chk1) || (chk == chk2))
{

alert("success");

return;

}
else
{
alert("failure");
document.getElementById('question').innerHTML= '';
document.getElementById('ans1').value = '';
  document.getElementById('ans2').value = '';
MakeRequest();

}
}

</script>


</head>


<body onload = "MakeRequest();">

<form name="fcap"
      id="signup" action="post" onsubmit="return false;">
<div id="question"></div>
        <input type="text"
               name="capt"
               id="capt"
               size="40"
               maxlength="100"
               onkeyup="alert(hex_md5(this.form.capt.value))"
onkeypress="return handleKeyPress(event);"/>


         <input name="ans1" id="ans1" type="hidden" value="">
         <input name="ans2" id="ans2" type="hidden" value="">
         <input name="hash" id="hash" type="hidden" value="">
         <input type="button"
            onClick="check();" value="submit"  >
</form>

</body>
</html>

*fn.php*

<?php
if($_GET['id'] == 1) {
/* load captcha using web service */
$url = 'http://textcaptcha.com';
$xml = new SimpleXMLElement($url,null,true);

/* display question as part of form */
$question = (string) $xml->question;
/* ... [snip] ... */

/* store answers in session */
$ans = array();
foreach ($xml->answer as $hash) {
$ans[] = $hash;
}
$_SESSION['captcha'] = $ans;
list ($ans1, $ans2) = $ans;
echo $question."<#>".$ans1."<#>".$ans2;
}
?>

now i click on submit button it passed check function

tell
bye



On Fri, Sep 5, 2008 at 9:58 PM, Michael Geary <[EMAIL PROTECTED]> wrote:

>  I believe your code would look something like this. You didn't show where
> your event handlers are set up, so I'm assuming that you want the check()
> function to be run whenever any of the three checkboxes is clicked, or
> whenever the Enter key is pressed when any of the three has the focus. (I
> added the spacebar since that toggles a checkbox.) If you currently have
> inline event handlers that call your handleKeyPress and onclick functions,
> you won't need them.
>
>     $('#question,#ans1,#ans2')
>         .click( function() {
>             check();
>         }).keypress( function( event ) {
>             var key = event.which;
>             if( key == 13  ||  key == 32 )
>                 check();
>         });
>
>     function check() {
>         var chk = $('#hash').val();
>         if( chk == $('#ans1').val()  ||  chk == $('#ans2').val() )
>             return;
>
>         setQAA( '', '', '' );
>
>         $.ajax({
>             url: 'fn.php?id=1',
>             dataType: 'text',
>             success: function( text ) {
>                 var values = text.split('<#>');
>                 setQAA( values[0], values[1], values[2] );
>             },
>             error: function( xhr, status, error ) {
>                 alert( 'Error: status code is ' + status );
>             }
>         });
>     }
>
>     function setQAA( q, a1, a2 ) {
>         $('#question').html( q );
>         $('#ans1').val( a1 );
>         $('#ans2').val( a2 );
>     }
> A little cleaner this way, isn't it? :-)
>
> -Mike
>
>  ------------------------------
> *From:* [email protected] [mailto:[EMAIL PROTECTED] *On
> Behalf Of *psarun kumar
> *Sent:* Friday, September 05, 2008 4:51 AM
> *To:* [email protected]
> *Subject:* [jquery-dev] how to convert this code to jquery
>
>  hi,
> any one tell how convert below code in jquery
>
> var XMLHttpArray = [
>         function() {return new XMLHttpRequest();},
>         function() {return new ActiveXObject("Msxml2.XMLHTTP");},
>         function() {return new ActiveXObject("Msxml2.XMLHTTP");},
>         function() {return new ActiveXObject("Microsoft.XMLHTTP");}
> ];
> function createXMLHTTPObject(){
>         var xmlhttp = false;
>         for(var i=0; i<XMLHttpArray.length; i++){
>                 try{
>                         xmlhttp = XMLHttpArray[i]();
>                 }catch(e){
>                         continue;
>                 }
>                 break;
>         }
>         return xmlhttp;
> }
> function AjaxRequest(url,method){
>         var req = createXMLHTTPObject();
>         req.onreadystatechange= function(){
>
>
>              if (req.readyState == 4){
>        if (req.status == 200){
>        var resarray = req.responseText.split("<#>");
>     document.getElementById('question').innerHTML= resarray[0];
>     document.getElementById('ans1').value = resarray[1];
>     document.getElementById('ans2').value = resarray[2];
>        }
>
>        else {
>          alert("Error: status code is " + req.status);
>
>        }
>         }
>         };
>         req.open(method,url,true);
>         //req.setRequestHeader('User-Agent', 'My XMLHTTP Agent');
>         req.setRequestHeader("Content-Type", "text/html");
>         req.send(null);
> }
> function AjaxResponse(req){
>         var respXML=req.responseXML;
>         if(!respXML) {return;}
>         var respVAL=respXML.getElementsByTagName('family')[0]
> .getAttribute('result');
>         document.getElementById("status").innerHTML += respVAL;
> }
> function ClearResponse(){
>         mdiv=document.getElementById("status");
>         mdiv.innerHTML = "";
> }
> function MakeRequest(){
>
>         AjaxRequest("fn.php?id=1","get");
> }
>
>
>   function handleKeyPress(e){
> var key=e.keyCode || e.which;
> if (key==13){
>
> check();
> //form.submit();
> //return false;
>
>
> }
> }
>
>
> function onclick(event) {
> check();
> }
>
>
> function check()
> {
> var chk = document.getElementById('hash').value ;
>
> var chk1 = document.getElementById('ans1').value;
>
> var chk2 =document.getElementById('ans2').value;
>
>
> if((chk == chk1) || (chk == chk2))
> {
> return;
>
> }
> else
> {
>
> document.getElementById('question').innerHTML= '';
> document.getElementById('ans1').value = '';
>   document.getElementById('ans2').value = '';
> MakeRequest();
>
> }
> }
>
> bye
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to