joashjohn
03-01-2012, 02:15 AM
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 :
<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.
devnull69
03-01-2012, 07:55 AM
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.
<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">
Philip M
03-01-2012, 08:57 AM
I have the idea that the OP thinks that "hidden" means somehow encrypted or secure.
joashjohn
03-01-2012, 04:47 PM
Hi, this work however I would like to be able to add many onchange events into the seem input, so this should work :
<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.
Philip M
03-01-2012, 04:51 PM
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.
joashjohn
03-01-2012, 05:22 PM
I mean this 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 :
<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.
Philip M
03-01-2012, 05:28 PM
Yes, you cannot have onchange twice. But one onchange event can trigger multiple actions, separated by ;. The first code is correct.