Forum Moderators: open

Message Too Old, No Replies

duplicate a field content to another field

         

virtuals

1:30 pm on Aug 7, 2005 (gmt 0)

10+ Year Member



I need a script which duplicates an input content to another one in the same page.

(It would be better if this could happen live. I mean as the user is filling the first field the other filed gets filed to, letter by letter.)

Thanks

whoisgregg

3:26 am on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know if this is cross-browser or not, but it works in Firefox and Safari. I also imagine there would be a way to write this where it could automagically push the source input data into any type of element (.value, .innerHTML, or .innertext) but I couldn't figure out how to get the type of an object. :/

<input id="src" size="24" onkeyup="mimicValue('src','dest')" />
<input id="dest" size="24" disabled="true" />
<script>
function mimicValue(src,dest){
var s = document.getElementById(src);
var d = document.getElementById(dest);
d.value=s.value;
}
</script>

virtuals

6:30 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



Thanks a lot! It was very nice of you sharing this code.
It's just what I needed, and it works on IE too.

One more question on this issue:
How can I omit special phrases from the duplicated content?
My first filed is a url field I want the second filed to be only the domain name so I have to omit "http://" , "www." , ".com" ".net" ".org"

whoisgregg

12:35 am on Aug 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not that good at regular expressions, but I'm quite certain that having it update on every key press to only show the hostname will not work as expected.

It couldn't simply remove the strings 'http://', 'www.', and all variations of '.TLD' because the real hostname could have those in it as legitimate subdomains. The most immediate example I can think of is news.com.com but I'm sure there are others.

virtuals

8:45 am on Aug 12, 2005 (gmt 0)

10+ Year Member



Can I use this [webmasterworld.com]metod to do what I want? How?

Thank you