Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data from textfield

Status
Not open for further replies.

macluv22

Programmer
Joined
Feb 28, 2002
Messages
7
Location
NL
Hi,

Does somebody know how to get data from a textfield (from another html-page)? Please check this example:


login.html
=======
<form method=&quot;post&quot; action=&quot;verify.html&quot; name=&quot;veri&quot;>
Username: <INPUT type =&quot;text&quot; name=&quot;username&quot;>
<p>
Password: <INPUT type =&quot;text&quot; name=&quot;password&quot;>
<P>
<input type=&quot;submit&quot; value=&quot; Log in &quot;>


verify.html
========
username = document.veri.username.value;
password = document.veri.password.value;

if (username ==&quot;administrator&quot; && password == &quot;whatever&quot;)
{
window.alert (&quot;Yo&quot;!);
}

I hope someone can help me. Thanks!!!

-macluv22

 
use this as your form-opening tag:

<form method=&quot;get&quot; action=&quot;success.html&quot; name=&quot;veri&quot; onsubmit=&quot;return validateForm(this.username.value, this.password.value);&quot;>

and write a validateForm function something like this:

function validateForm(username, password){
if (username == &quot;administrator&quot; && password == &quot;whatever&quot;)
{
window.alert (&quot;Yo!&quot;);
return true;
}
else
{
window.alert (&quot;try again&quot;);
return false;
}
}

Visitors will only be sent to success.html if they enter the correct username/password combination.

Make sure you put the function in a separate *.js file and include it in your html code so that they can't do a &quot;view-source&quot; to get the correct password ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top