Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing values to a function and reading them

    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!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    First we would need to see what the DoLogin() function actually contains. Post the javascript for that. We aren't psychic you know.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You don't need window there. That isn't what you originally asked either, you asked this
    Quote Originally Posted by coldskool
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •