Log in

View Full Version : Dynamic Javascript link



ejohnson747
09-27-2009, 08:21 PM
Hello,

I am new to javascript and am trying to create a custom log in for my ftp site. Im trying to make a form with two fields, username and password, then create a dynamic link attached to the submit button that would utilize the browser's FTP client to log them in to the FTP site. The link should look like this:

"ftp://[username]:[password]@domainName.com" where [username] would be the text entered in the username field and [password] the text from the password field.

Here is how it looks now:


<p><form name="f" onsubmit="MM_openBrWindow">
Username:
<input name="u" type="text"/>
<br/>
Password:
<input name="p" type="password"/>
<input type="button" onClick="MM_openBrWindow('ftp://')" value="login"/>
</form></p>

<script type=text/javascript>
-->
var user = document.f.u.value+("@exponentialintelligence.net");
var pass = document.f.p.value;
function MM_openBrWindow(theURL) { //v2.0
window.open(theURL+var user+":"+var pass+("@exponentialintelligence.net");
}
//-->
</script>

Can anyone help me please???

jlizarraga
09-27-2009, 09:59 PM
Try this.

Change:

window.open(theURL+var user+":"+var pass+("@exponentialintelligence.net");

To:

window.open(theURL+user+":"+pass+"@exponentialintelligence.net");

ejohnson747
09-27-2009, 11:21 PM
UPDATE:

ok so i changed some things around and got the user defined variables to show up in the URL. :



<p><form name="f" onsubmit="MM_openBrWindow()" method="post">
Username:
<input name="u" type="text"/>
<br/>
Password:
<input name="p" type="password"/>
<input type="submit" onClick="MM_openBrWindow()" value="login"/>
</form></p>

<script type=text/javascript>
-->

function MM_openBrWindow() {
if (document.f.u.value == ""){
alert("Username is Required");
return;
}
if (document.f.p.value == ""){
alert("Password is Required");
return;
}
window.open("ftp://"+document.f.u.value+":"+document.f.p.value+"@ftp.exponentialintelligence.net");
}
//-->
</script>



But now the browser's FTP client is acting funny. If I try logging in through the form, (without adding @domainName.com after the username, it automatically starts a download of a blank text document.
But if I type the same URL (ftp://username:password@ftp.domainName.com)
directly into the browser, it loads a dialog box saying my username and password are incorrect.

If I enter the username followed by @domainName.com in this dialogue box, it will log in successfully. But If I type the same syntax (ftp://username@domainName.com:password@ftp.domainName.com) directly into the browser, there is an error message that says page cant be shown.

Does anyone have any experience using a web browser to connect to and FTP server?

(I am using the latest version of Safari but the majority of the people using this will be on IE.)