PDA

View Full Version : picture onclick in javascript


bahy
04-22-2003, 06:04 AM
I am having a small problem with the javascript please help me .
In a big page i divided into 3 part , above , left and right .
On the left there is always a "login form" for user to enter their username and password to login . The code for the login form is below :


<form name="o">
<font size=2 face=Verdana><strong>::<a href="register.php">SIGN UP</a></strong></font>
<font size=1 face=Verdana><br><b>Tên truy cập:</b></font>
<input type=text size=8 name="usernamen"><br>
<font size=1 face=Verdana><b>Mật khẩu &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</b></font>
<input type=password size=8 name=passwordn><br>
<img name =signin src=signin.jpg border=0 alt="Click vào để đăng nhập;" onclick = login()>
</form>
<script language="javascript">
<!--
function login()
{
window.location = "login.php?username=" + document.o.usernamen.value +"&password=" + document.o.password.value
}

-->
</script>



also i use a javascript function generate when the user click on the picture signin.jpg . that will lead the user to another page :
"login.php?username=<?>&password=<?>"
while both of the <?> are the value i want to get from the "usernamen" and the "passwordn" in the o form ( i am using strange name , plz forgive about this - so i did put them into quotes). The javascript above is to do that . it will get the value from the specified fields and pass to the window.location function .
But u know ? When i clicked on the signin.jpg , it appeared the "Error on the page" in the status bar .
I am know only little of javascript , and now don't know how to solve this . So i came here and asking for help .

A1ien51
04-22-2003, 06:21 AM
first
you should use quotes around your onclick

onclick="fn()"

second you should use

window.location.href =

or

document.location.href =

third

you should put quotes around all your attirbutes in the tag
name="word" (good practice"

fourth
I would get rid of the
<!--
-->

I think that should help you out without looking at it very hard

A1ien51

glenngv
04-22-2003, 06:34 AM
<form name="o" action="login.php" method="post">
...

<input type="image" src="signin.jpg" border="0" alt="Click vào để đăng nhập;">
</form>

for security, you should use the POST method not the default GET in order for the fields to be passed as form data not as querystring in the URL. remember, you are passing the password.
in the login.php page, you should get the values via POST not GET.

bahy
04-22-2003, 05:08 PM
Can u tell me how do we know how long the user have been logged in with PHP session ? I used the session start iun the login page and all other pages that having user authoration .
I registered the username , not the timer , will it return the wrong way to count the time the user has been logged on ?