View Full Version : changing form values with onChange

06-08-2003, 08:47 AM
I'm having a hard time changing the value of a hidden form element with the onChange event handler. The form pretty much looks like this:

<form action="redirect.php" method="post" name="admin">
<input type="hidden" name="purpose" value="update_users">
<input type="hidden" name="0-id" value="1">
<input type="hidden" name="0-changed_pass">
<input type="text" name="0-user" value="jseay"></td>
<input type="password" name="0-pass" value="passwerd" onChange="document.admin.0-changed_pass.value='changed'">
<input type="checkbox" name="0-u_admin" value="y" checked>
<input type="checkbox" name="0-s_admin" value="y" checked>
<input type="checkbox" name="0-n_admin" value="y" checked>

And when I submit the form, if the 0-pass value has been changed, it doesn't seem to effect the value of the hidden element 0-changed_pass. Any idea why that would be? Thanks.

Mr J
06-08-2003, 09:32 AM
I changed 2 things, the 0 (zero) to a letter o and the minus - to an underscore_

You had


which would read,

onchange document.admin.0 minus changed_pass.value equals changed

The zero effects as well

Please try the following

form action="redirect.php" method="post" name="admin">
<input type="hidden" name="purpose" value="update_users">
<input type="hidden" name="o_id" value="1">
<input type="hidden" name="o_changed_pass">
<input type="text" name="o_user" value="jseay"></td>
<input type="password" name="o_pass" value="password" onChange="document.admin.o_changed_pass.value='changed'">
<input type="checkbox" name="o_u_admin" value="y" checked>
<input type="checkbox" name="o_s_admin" value="y" checked>
<input type="checkbox" name="o_n_admin" value="y" checked>

06-08-2003, 05:18 PM
Well I need the zero for counting purposes on the next script but I did change all the hyphens to underscores in the elemt names but it still doesn't respond. I mean for the most part it works fine, but the value of that hidden form element never does get changed regardless of how many times I change the password field.:confused:

Mr J
06-08-2003, 05:58 PM
Did you try it as I posted it before you changed the o's back to zeros

Mr J
06-08-2003, 06:06 PM
Could you not do something like this

<form action="redirect.php" method="post" name="admin">
<input type="hidden" name="purpose" value="update_users">
<input type="hidden" name="_0_id" value="1">
<input type="hidden" name="_0_changed_pass">
<input type="text" name="_0_user" value="jseay"></td>
<input type="password" name="_0_pass" value="password" onChange="document.admin._0_changed_pass.value='changed'">
<input type="checkbox" name="_0_u_admin" value="y" checked>
<input type="checkbox" name="_0_s_admin" value="y" checked>
<input type="checkbox" name="_0_n_admin" value="y" checked>

Use the link to check

<a href="#null" onclick="alert('_0_changed_pass value\n\n=\n\n'+admin._0_changed_pass.value)">CLICK</a>

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum