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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Capture user input into hidden tag

    Hi
    I have a form with some input tags, and when the user submit the form I which if a new hidden tag get submitted with the value the user did tip.

    I am thinking for doing that but not sure if it is the right thing :

    Code:
    <form method="POST"
    
    <input type="text" name="{actionForm.Name}" id="username">
    <input type="password" name="{actionForm.Passwd}" id="password">
    
    <input type="hidden" name="usernameh" value="document.getElementById('username')">
    <input type="hidden" name="passwordh" value="document.getElementById('password')">
    </form>
    Is it alright ? I mean when the user enter the username and password, the hidden tags should contain those two values that the user has made.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    I don't understand why you want to do that. The first two fields already contain what the user typed and will already be submitted.

    Besides, you cannot have a Javascript command as a value, so this won't work. You'd have to implement a piece of Javascript to copy the content of the first two fields onchange.
    Code:
    <input type="text" name="{actionForm.Name}" id="username" onchange="document.getElementsByName('usernameh')[0].value = this.value">
    <input type="password" name="{actionForm.Passwd}" id="password" onchange="document.getElementsByName('passwordh')[0].value = this.value">

  • Users who have thanked devnull69 for this post:

    joashjohn (03-01-2012)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,170
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    I have the idea that the OP thinks that "hidden" means somehow encrypted or secure.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    joashjohn (03-01-2012)

  • #4
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi, this work however I would like to be able to add many onchange events into the seem input, so this should work :

    Code:
    <input type="text" name="{actionForm.Name}" id="username" onchange="document.getElementsByName('usernameh1')[0].value = this.value; document.getElementsByName('usernameh2')[0].value = this.value">
    <input type="password" name="{actionForm.Passwd}" id="password" onchange="document.getElementsByName('passwordh1')[0].value = this.value; document.getElementsByName('passwordh2')[0].value = this.value">
    I just added the seem call of document.getElementsByName separated by a ; so it is wrong to have many onchange attributes into the seem input tag.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,170
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Quote Originally Posted by joashjohn View Post
    Hi, this work however I would like to be able to add many onchange events into the seem input, so this should work :

    I just added the seem call of document.getElementsByName separated by a ; so it is wrong to have many onchange attributes into the seem input tag.
    I think that there is a language problem here. What is "seem input tag" supposed to be?

    name="{actionForm.Name}" is not valid syntax.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    joashjohn (03-01-2012)

  • #6
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I mean this code :

    Code:
    <input type="text" name="{actionForm.Name}" id="username" onchange="document.getElementsByName('usernameh1')[0].value = this.value; document.getElementsByName('usernameh2')[0].value = this.value">
    <input type="password" name="{actionForm.Passwd}" id="password" onchange="document.getElementsByName('passwordh1')[0].value = this.value; document.getElementsByName('passwordh2')[0].value = this.value">
    is good but this one isn't because onchange appear two times :

    Code:
    <input type="text" name="{actionForm.Name}" id="username" onchange="document.getElementsByName('usernameh1')[0].value = this.value" onchange="document.getElementsByName('usernameh2')[0].value = this.value">
    <input type="password" name="{actionForm.Passwd}" id="password" onchange="document.getElementsByName('passwordh1')[0].value = this.value" onchange="document.getElementsByName('passwordh2')[0].value = this.value">
    For the brackets {actionForm.Something} it is used just because i code in jsp that is all the story don't bother with it.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,170
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    Yes, you cannot have onchange twice. But one onchange event can trigger multiple actions, separated by ;. The first code is correct.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    joashjohn (03-01-2012)


  •  

    Posting Permissions

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