...

View Full Version : Passing values to a function and reading them



coldskool
12-03-2006, 10:18 AM
Hi All,
New user here.. I have a question on how to pass values to my javascript function.

I have this button:
<input type="button" value="Login" Onclick="DoLogin(this.value)"/>

But how would I pass the value of two other text fields instead of passing the value of the button? For instance If my form was:

<input type="text" name="username" />
<input type="password" name="password"/>
<input type="button" value="Login" Onclick="DoLogin(What do I put here?)"/>

And also, what about the function itself, currently it reads:

function DoLogin(str)

How should the function get these values Im passing in?

Thanks!

_Aerospace_Eng_
12-03-2006, 10:27 AM
First we would need to see what the DoLogin() function actually contains. Post the javascript for that. We aren't psychic you know.

coldskool
12-03-2006, 10:42 AM
I figured it out .. if anyone is interested the code for the button would be:

Onclick="DoLogin(window.document.f1.username.value)"

f1 is the name of the form.

_Aerospace_Eng_
12-03-2006, 08:50 PM
You don't need window there. That isn't what you originally asked either, you asked this

But how would I pass the value of two other text fields instead of passing the value of the button? For instance If my form was:
Had you asked about only one field then I could have told you that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum