0

I just want to know how can i link two variables in jquery using .link() http://api.jquery.com/link/.

I have two variable var name; and var firstname; , i should link "name" to "firstname". If i made any changes to "name" means it should reflect in "firstname" and vise versa.

Amar
  • 1,906
  • 2
  • 16
  • 26

1 Answers1

0

I don't have much experience with the link() plugin for jQuery, but it seems that that plugin is designed more for linking user interface elements to variables in Javascript, not for linking two variables together so that when one changes value the second one will follow suit.

What are you trying to do exactly? The point of variables would be to contain, well, variable data, and if you're trying to access a variable called firstname which would be adjusted by another variable in its scope called name, then you could (and should) rather just access the name variable directly, and not attempt to create copies of variables.

Chris Kempen
  • 9,491
  • 5
  • 40
  • 52
  • I want to do this Data = {FirstName:"firstname",LastName:"lastname"}; var firstname = // here i want to link Data's FirstName. var lastname = // here i want to link Data's LastName. Is it possible to do something like this? – Amar Jan 30 '12 at 15:43
  • Again I'll ask, what are you trying to achieve? No, there is no clear way to 'link' variables, and there doesn't seem to be any point to linking two variables in the same scope together if you can just access the original one in the first place. Maybe a better description and more detail in your first question would be advisable, if only to avoid a down vote. – Chris Kempen Jan 31 '12 at 09:30
  • Could you please check this forum http://stackoverflow.com/questions/9141889/binding-a-javascript-objects-property That is what am trying to do. – Amar Feb 07 '12 at 10:16