cant refresh captcha image

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mitchell
    New Member
    • Oct 2007
    • 18

    cant refresh captcha image

    hi

    i m using IE 6.0.
    i want to refresh just the captcha part when the user clicks on an image.

    i searched for articles on it and got a fairly good understanding of it.
    but i m still unable to get any results.

    i have used Simple AJAX Code-Kit (SACK) (http://www.twilightuniverse.com/)

    my code:

    head part:::



    [code=html]
    <head>

    <script type="text/javascript" src="ajax.js"></script>
    // i have saved ajax.js in my common website folder which contains all the files

    <script type="text/javascript">

    var ajax = new sack();
    var contentObj;

    function showContent()
    {
    contentObj.inne rHTML = ajax.response;
    }


    function showWaitMessage ()
    {
    contentObj.inne rHTML = 'Loading image...Please wait';

    }

    function getAjaxFile(fil eName)
    {
    ajax.requestFil e = fileName;
    ajax.onCompleti on = showContent;
    ajax.onLoading = showWaitMessage ;
    ajax.runAJAX();
    }



    function captcha()
    {
    getAjaxFile(cap tcha.php);
    }



    function initAjaxDemo()
    {
    contentObj = document.getEle mentById('div_c aptcha');
    }


    window.onload = initAjaxDemo;

    </script>
    </head>
    [/code]
    -------------------------

    body part:::::


    [code=html]<div id="div_captcha ">
    default text
    </div>

    <img alt="Request new image" src="req_im.gif " onclick="captch a()">[/code]


    but the script is not working
    and it is not loading the contents of captcha.php on clicking on the image.

    please help
    Last edited by gits; Oct 21 '07, 08:23 PM. Reason: added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    What does captcha.php return?

    Comment

    • mitchell
      New Member
      • Oct 2007
      • 18

      #3
      does the captcha.php have to return something
      can you please elaborate on that.
      i thought it can be just a simple file

      contents of captcha.php::
      [code=javascript]<script type="text/javascript">

      var string='';
      var i;
      var chars =

      "0123456789ABCD EFGHIJKLMNOPQRS TUVWXTZabcdefgh iklmnopqrstuvwx yz";
      var ran_unrounded;
      var ran_number;
      var rnum;
      for(i=0;i<5;i++ )
      {



      rnum= Math.floor(Math .random() * chars.length);
      string += chars.substring (rnum,rnum+1);

      ran_unrounded=M ath.random()*3;
      ran_number=Math .floor(ran_unro unded);
      document.write( chars.substring (rnum,rnum+1));

      }

      </script>[/CODE]

      please help...!!!
      Last edited by acoder; Oct 22 '07, 05:58 PM. Reason: Added code tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by mitchell
        does the captcha.php have to return something
        can you please elaborate on that.
        i thought it can be just a simple file
        Sorry, that's what I meant. It should echo something. If you run the file on its own, it should display the captcha characters on screen.

        Why are you using JavaScript to generate this when it's a PHP file, but that's a side issue.

        Comment

        • mitchell
          New Member
          • Oct 2007
          • 18

          #5
          i have changedn the contents of captcha.php
          i have not done the whole thing
          but i m just generating random nos. right now
          this file when executed displays the random nos.
          but it is still not showing up inside the div tag

          contents of captcha.php


          [PHP]<?php

          srand(time());

          for($i=0;$i<5;$ i++)
          {
          $string=(rand() %6);
          echo $string;


          }

          ?>
          [/PHP]
          i cant find any error in the code
          then whats happening????
          please help
          Last edited by acoder; Oct 23 '07, 08:37 AM. Reason: Added code tags

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            So do you get any error messages?

            Does the wait message show up?

            Comment

            • mitchell
              New Member
              • Oct 2007
              • 18

              #7
              there r no error messages
              but in the status bar of Internet Explorer it shows error on page.

              i m sending the whole file now.

              if u can spare time to look at it.
              i will be really grateful
              i have made the relevant section bold.
              //register.php
              [HTML]<html>
              <head>

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

              [/HTML][CODE=javascript]<script type="text/javascript">

              var ajax = new sack();
              var contentObj;


              function showContent()
              {

              contentObj.inne rHTML = ajax.response;

              }


              function showWaitMessage ()
              {
              contentObj.inne rHTML = 'Finding article.....<br >Please wait';

              }

              function getAjaxFile(fil eName)
              {
              ajax.requestFil e = fileName;
              ajax.onCompleti on = showContent;
              ajax.onLoading = showWaitMessage ;
              ajax.runAJAX();
              }



              function CAPTCHA()
              {
              getAjaxFile(cap tcha.php);
              }



              function initAjaxDemo()
              {
              contentObj = document.getEle mentById('div_c aptcha');
              }


              window.onload = initAjaxDemo;

              </script>[/CODE]


              [CODE=javascript]<script type="text/javascript">
              function validate_form(t hisform)
              {
              var check=true;
              with (thisform)
              {
              with (email)
              {

              if (value==null||v alue=="")
              {
              document.getEle mentById('div_e mail').style.di splay="block";
              document.getEle mentById('div_e mail').innerHTM L="<font color='red'>Use rname Required</font>";
              check=false;
              }
              else
              {
              document.getEle mentById('div_e mail').style.di splay="none";
              }
              }

              with (password)
              {

              if (value==null||v alue=="")
              { document.getEle mentById('div_p assword').style .display="block ";
              document.getEle mentById('div_p assword').inner HTML="<font color='red'>Pas sword

              Required</font>";
              check=false;
              }
              else
              {
              document.getEle mentById('div_p assword').style .display="none" ;
              }
              }

              with (repassword)
              {

              if (value==null||v alue=="")
              { document.getEle mentById('div_r epassword').sty le.display="blo ck";
              document.getEle mentById('div_r epassword').inn erHTML="<font color='red'>Pas sword

              Required</font>";
              check=false;
              }
              else if(value!=passw ord.value)
              { document.getEle mentById('div_r epassword').sty le.display="blo ck";
              document.getEle mentById('div_r epassword').inn erHTML="<font color='red'>Pas swords don't match

              </font>";
              check=false;
              }

              else
              {
              document.getEle mentById('div_r epassword').sty le.display="non e";
              }

              }


              with (securityq)
              {

              if (value==null||v alue=="")
              { document.getEle mentById('div_s ecurityq').styl e.display="bloc k";
              document.getEle mentById('div_s ecurityq').inne rHTML="<font color='red'>Sec urity question

              Required</font>";
              check=false;
              }
              else
              {
              document.getEle mentById('div_s ecurityq').styl e.display="none ";
              }

              }


              with (securitya)
              {

              if (value==null||v alue=="")
              { document.getEle mentById('div_s ecuritya').styl e.display="bloc k";
              document.getEle mentById('div_s ecuritya').inne rHTML="<font color='red'>Sec urity answer

              Required</font>";
              check=false;
              }
              else
              {
              document.getEle mentById('div_s ecuritya').styl e.display="none ";
              }

              }


              if (months.value== "MM"||days.valu e=="DD"||years. value=="YYYY")
              {
              document.getEle mentById('div_d ob').style.disp lay="block";
              document.getEle mentById('div_d ob').innerHTML= "<font color='red'>Dat e Of Birth

              Required</font>";
              check=false;
              }
              else
              {
              document.getEle mentById('div_d ob').style.disp lay="none";
              }

              if (gender[0].checked==false )
              {
              if(gender[1].checked==false )
              { document.getEle mentById('div_g ender').style.d isplay="block";
              document.getEle mentById('div_g ender').innerHT ML="<font color='red'>Gen der

              Required</font>";
              check=false;
              }
              else
              {
              document.getEle mentById('div_g ender').style.d isplay="none";
              }

              }
              else
              {
              document.getEle mentById('div_g ender').style.d isplay="none";

              }

              with (visual)
              {
              var uppervalue=valu e.toUpperCase() ;
              if (value==null||v alue=="")
              { document.getEle mentById('div_v isual').style.d isplay="block";
              document.getEle mentById('div_v isual').innerHT ML="<font color='red'>Tex t field needs to be

              filled</font>";
              check=false;
              }
              else if (uppervalue!=st ring.toUpperCas e())
              { document.getEle mentById('div_v isual').style.d isplay="block";
              document.getEle mentById('div_v isual').innerHT ML="<font color='red'>Str ing didn't

              match</font>";
              check=false;
              }
              else
              {
              document.getEle mentById('div_v isual').style.d isplay="none";
              }

              }



              }


              return check;
              }[/code]
              [code=javascript]function agreeTerms()
              {

              if(document.for m1.terms.checke d == true)
              {
              document.getEle mentById('div_t erms').style.di splay="none";

              document.form1. register.disabl ed = false;

              }

              if(document.for m1.terms.checke d == false)
              {
              document.getEle mentById('div_t erms').style.di splay="block";
              document.getEle mentById('div_t erms').innerHTM L="<font color='red'>You need to agree to have a <font

              color='white'> Web<font color='orange'> mail</font></font> account </font>";
              document.form1. register.disabl ed = true;
              }

              }
              </script>
              [/CODE][HTML]</head>

              <body bgcolor="black" text="white" vlink="black" alink="black">

              <table width="1230" border="2" cellspacing="0" cellpadding="0" align="center" name="header" background="bg_ header.jpg">
              <tr>
              <td><img src="top.jpg"></td>
              </tr>
              </table>

              <font color="white">
              <br><br><br>
              <div align="center">
              Fields marked with asterisk(*) are compulsary.
              </div>


              <table align="center">
              <form name="form1" id="form1" action="http://localhost/website/reg-com.php" method="post" onsubmit="retur n validate_form

              (this)" >

              <tr>
              <td align="right" valign="bottom" ><font color="white">U sername *</font></td>
              <td><div name="div_email " id="div_email"> </div><input type="text" name="email" id="email" maxlength="15">
              </td>
              </tr>

              <tr>
              <td align="right" valign="bottom" ><font color="white">P assword *</font></td>
              <td><div name="div_passw ord" id="div_passwor d"></div><input type="password" name="password" id="password"

              maxlength="15"> </td>
              </tr>

              <tr>
              <td align="right" valign="bottom" ><font color="white">R etype Password *</font></td>
              <td><div name="div_repas sword" id="div_repassw ord"></div><input type="password" name="repasswor d" id="repassword "

              maxlength="15"> </td>
              </tr>

              <tr>
              <td align="right" valign="bottom" ><font color="white">E nter your Security Question*</font></td>
              <td><div name="div_secur ityq" id="div_securit yq"></div><input type="text" name="securityq " id="securityq" size="40"

              maxlength="25"> &nbsp;?
              </td>
              </tr>

              <tr>
              <td align="right" valign="bottom" ><font color="white">E nter your Security Answer*</font></td>
              <td><div name="div_secur itya" id="div_securit ya"></div><input type="text" name="securitya " id="securitya" size="10"

              maxlength="10">
              </td>
              </tr>


              <tr>
              <td align="right" valign="bottom" ><font color="white">D ate of Birth *</font></td>[/html]
              [html]<td>
              <div name="div_dob" id="div_dob"></div>
              <select name="months">
              <option value="MM" selected="selec ted">MM</option>
              <option label="Jan" value="01">Jan</option>
              <option label="Feb" value="02">Feb</option>
              <option label="Mar" value="03">Mar</option>
              <option label="Apr" value="04">Apr</option>
              <option label="May" value="05">May</option>
              <option label="Jun" value="06">Jun</option>
              <option label="Jul" value="07">Jul</option>
              <option label="Aug" value="08">Aug</option>
              <option label="Sep" value="09">Sep</option>
              <option label="Oct" value="10">Oct</option>
              <option label="Nov" value="11">Nov</option>
              <option label="Dec" value="12">Dec</option>
              </select>
              <select name="days">
              <option value="DD" selected="selec ted">DD</option>
              <option label="1" value="01">1</option>
              <option label="2" value="02">2</option>
              <option label="3" value="03">3</option>
              <option label="4" value="04">4</option>
              <option label="5" value="05">5</option>
              <option label="6" value="06">6</option>
              <option label="7" value="07">7</option>
              <option label="8" value="08">8</option>
              <option label="9" value="09">9</option>
              <option label="10" value="10">10</option>
              <option label="11" value="11">11</option>
              <option label="12" value="12">12</option>
              <option label="13" value="13">13</option>
              <option label="14" value="14">14</option>
              <option label="15" value="15">15</option>
              <option label="16" value="16">16</option>
              <option label="17" value="17">17</option>
              <option label="18" value="18">18</option>
              <option label="19" value="19">19</option>
              <option label="20" value="20">20</option>
              <option label="21" value="21">21</option>
              <option label="22" value="22">22</option>
              <option label="23" value="23">23</option>
              <option label="24" value="24">24</option>
              <option label="25" value="25">25</option>
              <option label="26" value="26">26</option>
              <option label="27" value="27">27</option>
              <option label="28" value="28">28</option>
              <option label="29" value="29">29</option>
              <option label="30" value="30">30</option>
              <option label="31" value="31">31</option>
              </select>
              <select name="years">
              <option value="YYYY" selected="selec ted">YYYY</option>
              <option label="1971" value="1971">19 71</option>
              <option label="1972" value="1972">19 72</option>
              <option label="1973" value="1973">19 73</option>
              <option label="1974" value="1974">19 74</option>
              <option label="1975" value="1975">19 75</option>
              <option label="1976" value="1976">19 76</option>
              <option label="1977" value="1977">19 77</option>
              <option label="1978" value="1978">19 78</option>
              <option label="1979" value="1979">19 79</option>
              <option label="1980" value="1980">19 80</option>
              <option label="1981" value="1981">19 81</option>
              <option label="1982" value="1982">19 82</option>
              <option label="1983" value="1983">19 83</option>
              <option label="1984" value="1984">19 84</option>
              <option label="1985" value="1985">19 85</option>
              <option label="1986" value="1986">19 86</option>
              <option label="1987" value="1987">19 87</option>
              <option label="1988" value="1988">19 88</option>
              <option label="1989" value="1989">19 89</option>
              <option label="1990" value="1990">19 90</option>
              <option label="1991" value="1991">19 91</option>
              <option label="1992" value="1992">19 92</option>
              <option label="1993" value="1993">19 93</option>
              <option label="1994" value="1994">19 94</option>
              <option label="1995" value="1995">19 95</option>
              <option label="1996" value="1996">19 96</option>
              <option label="1997" value="1997">19 97</option>
              <option label="1998" value="1998">19 98</option>
              <option label="1999" value="1999">19 99</option>
              <option label="2000" value="2000">20 00</option>
              <option label="2001" value="2001">20 01</option>
              <option label="2002" value="2002">20 02</option>
              <option label="2003" value="2003">20 03</option>
              <option label="2004" value="2004">20 04</option>
              <option label="2005" value="2005">20 05</option>
              </select></td>
              </tr>

              <tr>
              <td align="right" valign="bottom" ><font color="white">G ender *</td>
              <td>
              <div name="div_gende r" id="div_gender" ></div>
              <input type="radio" name="gender" id="gender" value='m'><font color="white"> male</font>
              <input type="radio" name="gender" id="gender" value='f'><font color="white"> female</font>
              </td>
              </tr>

              <tr>
              <td align="right" valign="bottom" ><font color="white">T ype the characters below *</font></td>
              <td valign="bottom" ><div name="div_visua l" id="div_visual" ></div><input type="text" name="visual" id="visual"></td>
              </tr>

              <tr>

              <td valign="top">(L etters are not case sensitive)&nbsp ;&nbsp;</td>

              <td valign="top">
              <div id="div_captcha ">
              <p>This will load the the content of external articles into this DIV</p>
              </div>
              </td>[/html]
              [html]<td>
              <img alt="Request new image" align="right" src="req_im.gif " onclick="CAPTCH A()">

              </td>

              </tr>

              <tr>
              <td></td>
              <td align="left">
              <textarea onfocus="this.r ows=30" border=1 style="text-align:left" rows="5" cols="55" style="color:wh ite;background-color:rgb

              (45,45,70); overflow:hidden " readonly onblur="this.ro ws=5">

              TERMS & CONDITIONS
              In order to use the Services, you must first agree to the Terms. You may not use the Services if you do not accept the Terms.

              1.You acknowledge and agree that if Webmail disables access to your account, you may be prevented from accessing the

              Services, your account details or any files or other content which is contained in your account.

              2.You agree that any registration information you give to Webmail will always be accurate, correct and up to date.

              3.You understand that by using the Services you may be exposed to Content that you may find offensive, indecent or

              objectionable and that, in this respect, you use the Services at your own risk.

              4.The Terms will continue to apply until terminated by either you or Google as set out below.

              5.Unless you have agreed otherwise in writing with Webmail, nothing in the Terms gives you a right to use any of Webmail’s

              trade names, trade marks, service marks, logos, domain names, and other distinctive brand features.
              </textarea>
              </td>
              </tr>

              <tr>
              <td align="right" valign="bottom" >
              <input type="checkbox" name="terms" id="terms" checked onclick="agreeT erms()">
              </td>
              <td>
              <div id="div_terms" name="div_terms " ></div>
              <font color="white">I agree to the terms and conditions.</font>
              </td>
              </tr>

              </table>


              <br>
              <div align="center">
              <input type="submit" name="register" id="register" value="register ">
              </div>
              </form>
              </font>
              </body>
              </html>[/HTML]


              //contents of captcha.php


              [PHP]<?php

              srand(time());

              for($i=0;$i<5;$ i++)
              {
              $string=(rand() %6);
              echo $string;


              }

              ?>[/PHP]
              Last edited by acoder; Oct 23 '07, 10:05 AM. Reason: Added code tags

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by mitchell
                there r no error messages
                but in the status bar of Internet Explorer it shows error on page.
                Double-click on the error icon. What does the error message say?
                Originally posted by mitchell
                i m sending the whole file now.
                Please use code tags when posting code:
                &#91;CODE=javas cript]
                Your JavaScript code goes here...
                [/CODE]

                Comment

                Working...