Results 1 to 7 of 7

Thread: realtime display md5

  1. #1
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default realtime display md5

    hello everyone,

    i'm looking for a script which display in real time md5 calculation.

    I already succed to do a simple form submit which return the result...
    but i would rather prefer to use an input field, with an Ajax based script checking and showing the result caracter by carcter (in an other div i guess).

    the purpuse of this is to avoid form and submit ...

    thanks for your help ^^
    Last edited by sfchun; 11-07-2008 at 02:36 AM.

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    md5.php:
    PHP Code:
    <?php
    $pswrd
    =$_POST['passwd'];
    echo 
    md5($pswrd);
    ?>
    Index:
    HTML Code:
    <script type="text/javascript">
    function showMd5(url)
    {
    var xmlHttp;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          return false;
          }
        }
      }
      xmlHttp.onreadystatechange=function()
        {
        if(xmlHttp.readyState==4)
          {
    	var el=document.getElementById('md5');
    	el.innerHTML=xmlHttp.responseText;
          }
        }
    
      xmlHttp.open("post",url,true);
    
      xmlHttp.send(null);
      }
    </script>
    <input type="password" name="passwd" onkeypress="showMd5('md5.php')">
    <h2 style="display:inline;">MD5 val is: </h3><h3 id="md5" style="display:inline;">&nbsp;</h3>
    Hope that helps.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. The Following User Says Thank You to rangana For This Useful Post:

    sfchun (11-07-2008)

  4. #3
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your quick reply rangana !

    But i think there is a little problem somewhere =P
    the code is displaying only blank encoded string...
    I mean , it does not update when i press a key
    Last edited by sfchun; 11-07-2008 at 04:33 AM.

  5. #4
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    It was my mistake. You need to pass the value of the textbox too. Add highlighted:
    Code:
    <input type="password" name="passwd" onkeypress="showMd5('md5.php',this.value)">
    ...and change this part:
    Code:
    function showMd5(url)
    .
    .
    .
    xmlHttp.open("post",url,true);
    to:
    Code:
    function showMd5(url,val)
    .
    .
    .
    xmlHttp.open("get",url+"?passwd="+val,true);
    ...and change md5.php to:
    PHP Code:
    <?php
    $pswrd
    =$_GET['passwd'];
    echo 
    md5($pswrd);
    ?>
    See if it helps.
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  6. The Following User Says Thank You to rangana For This Useful Post:

    sfchun (11-08-2008)

  7. #5
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    once again thanks for your help =P
    but i still have the same issue after updating code ^^;;

    hope i miss nothing, i'll copy paste what i have.

    index.htm
    Code:
    <script type="text/javascript">
    function showMd5(url,val)
    {
    var xmlHttp;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        try
          {
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        catch (e)
          {
          alert("Your browser does not support AJAX!");
          return false;
          }
        }
      }
      xmlHttp.onreadystatechange=function()
        {
        if(xmlHttp.readyState==4)
          {
            var el=document.getElementById('md5');
            el.innerHTML=xmlHttp.responseText;
          }
        }
    
      xmlHttp.open("get",url+"?passwd="+val,true);
    
      xmlHttp.send(null);
      }
    </script>
    <input type="password" name="passwd" onkeypress="showMd5('md5.php',this.value)">
    <h2 style="display:inline;">MD5 val is: </h3><br /><div id="md5" style="display:inline;">&nbsp;</div>
    md5.php
    PHP Code:
    <?php
    $pswrd
    =$_POST['passwd'];
    echo 
    md5($pswrd);
    ?>

  8. #6
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Replace highlighted with GET:
    Code:
    $pswrd=$_POST['passwd'];
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  9. The Following User Says Thank You to rangana For This Useful Post:

    sfchun (11-11-2008)

  10. #7
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    stupid me ... sorry =P

    thanks a lot, it works great

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •