House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Search cf-talk

February 09, 2010

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
   1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28             

Home / Groups / ColdFusion Talk (CF-Talk)

AutoFill

Author:
Raymond Camden
05/31/2009 05:54 PM

jQuery version... could be better probably. going to share this on InsideRIA in a bit as well. <script src="jquery/jquery.js"></script> <script> $(document).ready(function() {   $("#firstName").keyup(setProfile)   $("#lastName").keyup(setProfile)   $("#profileName").keypress(disableMe)    }) var doIt = true function setProfile() {   if(doIt) $("#profileName").val($("#firstName").val() + $("#lastName").val()) } function disableMe() { doIt=false } </script> first name <input type="text" name="First_name" id="firstName" ><br/> last name <input type="text" name="Last_name" id="lastName" /><br/> profile name<input type="text" name="Profile_name" id="profileName" /> > This may be ok, I use onkeypress to disable the code Charlie used. He > is right though, jQuery would make this a bit slimmer. :) > > I was about to hit send but... to be 100% anal, even this isn't > perfect. onkeypress will fire on ANY key press, so I may modify > profile name to add A and then delete A, and in theory I haven't > changed. I doubt you care about that though? > > <input type="text" name="First_name" id="firstName" > onblur="fillProfile()"/><br/> > <input type="text" name="Last_name" id="lastName" onblur="fillProfile()" /><br/> > > <input type="text" name="Profile_name" id="profileName" > onkeypress="disableIt()"/> > > <script> >        var doit=true > >        function disableIt() { >                doit=false >        } > >    function fillProfile() { >         if (doit) { >              document.getElementById('profileName').value = >                   document.getElementById('firstName').value + >                   document.getElementById('lastName').value; >         } >    } > </script> > > > >> Of course, if the user enters their last name first there, it won't work. ;) >> >> On Sun, May 31, 2009 at 4:36 PM, Charlie Griefer >> <charlie.griefer@gmail.com> wrote: >>> >>> >>> >>>> >>>> Summary: I am trying to autofill an input field based on the values of two >>>> other fields. >>>> >>>> Detail: I have two input fields called First_name and Last_name. I have a >>>> third field called Profile_name. I want to fill in the Profile_name to equal >>>> the value of the first two fields automatically when you lose focus on each >>>> of First_name and Last_name field. >>>> >>>> The new value of the Profile_name is a suggestion and the user may choose >>>> to overwrite it. If they go back and update the First_name and Last_name >>>> fields after the fact, I don't want to update the Profile_name field again. >>>> >>> >>> <input type="text" name="First_name" id="firstName" /> >>> <input type="text" name="Last_name" id="lastName" onblur="fillProfile();" /> >>> >>> <input type="text" name="Profile_name" id="profileName" /> >>> >>> <script> >>>     function fillProfile() { >>>          if (document.getElementById('profileName').value == "") { >>>               document.getElementById('profileName').value = >>>                    document.getElementById('firstName').value + >>>                    document.getElementById('lastName').value; >>>          } >>>     } >>> </script> >>> >>> >> > > > > -- > =========================================================================== > Raymond Camden, ColdFusion Jedi Master > > Email    : ray@camdenfamily.com > Blog      : www.coldfusionjedi.com > AOL IM : cfjedimaster > > Keep up to date with the community: http://www.coldfusionbloggers.org > -- =========================================================================== Raymond Camden, ColdFusion Jedi Master Email    : ray@camdenfamily.com Blog      : www.coldfusionj


Mailing Lists