...

View Full Version : Split up a FTP URL



Yorick
04-13-2005, 08:31 PM
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!

Harry Armadillo
04-13-2005, 09:38 PM
<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>

Yorick
04-14-2005, 12:57 PM
Wow, it works great! Many thanks!

Harry Armadillo
04-14-2005, 03:01 PM
You're welcome.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum