Forum Moderators: open

Message Too Old, No Replies

Other field value > hidden field value

         

atteso

7:49 am on Oct 27, 2004 (gmt 0)

10+ Year Member



I have a form where LOGIN is hidden field and EMAIL is a visible field.

How can I on submit form make the value entered in the EMAIL-field also be set in the hidden LOGIN-field?

whoisgregg

7:49 pm on Oct 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




document.getElementByID('login').value = document.getElementByID('email').value;

:)

atteso

7:44 am on Oct 28, 2004 (gmt 0)

10+ Year Member



Thank you! Can I put the script anywhere in the form?

whoisgregg

3:39 pm on Oct 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's real easy, just add an onsubmit to your form tag like so:

<form name="myform" onsubmit="return fillFields();">

And this script to the head of your document:


<script language=javascript>
function fillFields() {
document.getElementById('login').value = document.getElementById('email').value;
}
</script>

Note: my first post had a typo, the getElementById should use a lowercase 'd'.

atteso

1:19 pm on Oct 31, 2004 (gmt 0)

10+ Year Member



Hi again, It doesn´t work for me. :-(
Can you se what I´ve done wrong?

I want the email-field to be sent to the server as both email and login. (the loginfield should not be visible in the form) and as you can see I also want a verify email field.

Here´s part of the code

From the head:
<script language=javascript>
function fillFields() {document.getElementById('login').value = document.getElementById('email').value;}
</script>

From the form:
<form method="post" action="#*$!" name=pform onsubmit="return fillFields();">

<input type="hidden" name="action" value="#*$!">
<input type="hidden" name="regcode" value="">

<td>Email (used for login):</font><span class="style1">*</span></td>
<td><input name="_email" type="text" size="30"></font></td></tr>
size="30"></td>

<tr><td>Verify e-mail:<span class="style1">*</span></font></td>
<td><input name="_email2" type="text" size="30">
</font></td></tr>

<input type="submit" value="Send"></div></td></tr>
</table>

dcrombie

2:02 pm on Nov 1, 2004 (gmt 0)



The above code needs the fields to be flagged with "id='login'" or similar. I'd stick to the older methods.
EITHER of these should work - assuming your fields are something like the following:

<FORM ... > 
<INPUT type="hidden" name="login" ... >
...
<INPUT type="text" name="email" ... >
...
</FORM>

1) in the FORM tag:

<FORM ... onSubmit="this.login.value=this.email.value; return true;">

2) in the INPUT tag:

<INPUT name="email" ... onChange="this.form.login.value=this.value;">