Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Split up a FTP URL

    I have a javascript problem, i want, when i put a full FTP url in a input field. Javascript puts the pieces of the url in the input field where they belong.

    I'v made a page where you can see what i wan't. So this doesn't work, but maybe this makes it a bit clear.

    http://xrebuilding.klasa33.nl/adres.html

    A Javscript prompt is also good!

    Thanx in advance!

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <script>
    function splitAddress(){
      arr=new Array();
      document.getElementById('ftp').value.replace(/[^\/]*\/\/([^@]*@|)([^\/]*)(\/.*|)/,function(m,p1,p2,p3){if(p1)p1.replace(/([^:]*):?([^@]*)@/,function(m,p1,p2){arr=[p1,p2];return''});if(p2)p2.replace(/([^:]*)(:|)(.*)/,function(m,p1,p2,p3){arr[2]=p1;arr[3]=p3;return''});if(p3)arr[4]=p3;return''});
      document.getElementById('username').value=arr[0]||'';
      document.getElementById('password').value=arr[1]||'';
      document.getElementById('ip').value=arr[2];
      document.getElementById('port').value=arr[3]||'';
      document.getElementById('path').value=arr[4]||'';
      }
    </script>
    <table>
      <tr>
        <td><b>Volledig adres</b></td>
        <td colspan="5"><input id="ftp" name="ftp" type="text" value="ftp://username:password@ip:port/path/" size="88"></td>
      </tr>
    
      <tr>
        <td><input type="button" value="Convert" onclick="splitAddress()"></td>
      </tr>
      <tr>
         <td><b>IP</b></td>
         <td><input id="ip" name="ip" type="text" value=""></td>
         <td><b>Port</b></td>
         <td><input id="port" name="port" type="text" value="">  </td>
    
         <td><b>Username</b></td>
         <td><input id="username" name="username" type="text" value=""></td>
      </tr>
      <tr>
         <td><b>Password</b></td>
         <td><input id="password" name="password" type="text" value=""></td>
         <td><b>Path</b></td>
    
         <td><input id="path" name="path" type="text" value="">   </td>
         <td></td>
      </tr>
    </table>
    Last edited by Harry Armadillo; 04-13-2005 at 10:50 PM.

  • #3
    New Coder
    Join Date
    Apr 2005
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow, it works great! Many thanks!

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're welcome.


  •  

    Posting Permissions

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