Forum Moderators: open

Message Too Old, No Replies

changing value of a hidden field

         

lindajames

12:43 pm on Sep 15, 2004 (gmt 0)

10+ Year Member



i have a login form that has two textbox fields.

first field is called user
and second field is called password

and i also have a hidden field called host

i want the value of the hidden field "host" to change depending on what is entered as the value for "user".

the "user" field is where a user must enter a full email address and based on this i want to set the value of host field to "mail.domain.com"

so for example, if i typed my email address as something@yahoo.com in the user field, then just before i click on login it should set the value of the hidden field "host" to mail.yahoo.com

can anyone please tell me how i can do this, and it needs to be compatible with as many browsers as possible.

RonPK

12:58 pm on Sep 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Easy one ;). On submitting the form, call a function that sets the value of the "host" field to a substring of the value of the "user" field preceeded by 'mail.'.

<script type="text/javascript"> 
function myfunction(f) {
var u = f.user.value;
f.host.value = 'mail.' + u.substr(u.indexOf('@')+1);
}
</script>

<form action="..." onsubmit="myfunction(this)">
...

Bernard Marx

1:33 pm on Sep 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nowt wrong with that at all, but I want to exercise my weakling RegExp muscles,
so I'll just briefly mention:

f.host.value = f.user.value.replace(/.*@/,"mail.");

lindajames

11:43 am on Sep 17, 2004 (gmt 0)

10+ Year Member



Thanks RonPK, that script did perfectly, it works like clockwork

atteso

9:24 am on Oct 25, 2004 (gmt 0)

10+ Year Member



I have a very close problem:

How do I do if I want the hidden field (in this case: host) to get exactly the same value as entered in user field?