Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoFill

Status
Not open for further replies.

danarashad

Programmer
Nov 2, 2006
115
US
Can someone help me with this. I have a couple of form fields, that are the same. Meaning they are using the same data. So if someone types in fieldA, it appears in fieldB as well.

Name Building Name
Name:<input name="fieldA"> Name:<input name="fieldB">

Is it possible for a person to type in fieldA, and it appears in fieldB also.

Thanks
 
Yes it can be done, and here is a working example:

Code:
<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<script type="text/javascript">
function populate(obj) {
   document.getElementById("fieldB").value = obj.value;   
}
</script>
</head>
<body>
Name:<input onkeyup = "populate(this)" id="fieldA" />   
Name:<input id="fieldB" />

</body>
</html>

[monkey][snake] <.
 
Heh, or you can do what cLFlaVA did, which is way cleaner.

[monkey][snake] <.
 
Thanks man it works, I dont know javascript that well. Thanks again
 
maybe cleaner, but a function is always the way to go when you want dynamics. something like:

Code:
function copyOver( targ, src ) {
    targ.value = src.value;
}

Code:
<input type="text" name="blah" onkeyup="copyOver(this.form.blah2, this);" />

might be the best bet, if you need more than one instance.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top