Chris, >I am trying to make a plugin that will be used to generate a password. >After many days of deliberation I decided to call it >generate_password(). Now that I've got the name out of the way I'm >having a bit of trouble getting it to work right. > >You can see the behavior here: > >http://www.heyareyoulistening.com/generate_password/ > >Clearly, I don't want both "generate" buttons to generate text in the same >box.
You need to var the generate_to variable in the click handler. Currently it's a global variable, which makes the second instance overwrite the first instance. Change: generate_to = $(this).attr('for'); to: var generate_to = $(this).attr('for'); Also, I think I'd change the plug-in a bit. IMO, I would make more sense to use like: $("#button").generate_password("#passwordField", iLength); That way you can attach the behavior to any element. Also, by using a selector for the field to update, you could update multiple fields with the same value (in those cases where you had both a password and confirm password fields.) -Dan