Forum Moderators: open

Message Too Old, No Replies

Complex problem in jQuery

         

andregolvea

3:15 am on Aug 12, 2010 (gmt 0)

10+ Year Member



Hello, I have a problem that has been consuming me for days.

I have a div and the div has a style for it to be hidden ( .copy (display: none;) ).

I have a link (Add new) that when clicked, makes a clone of that div and removes the class "copy", causing the div to appear.

Inside this div, I have 4 checkbox and a text input. Clicking this checkbox, the values are displayed in this input text.

When I click once on "Add New", he makes sure, but if I click a second time on the link "Add New" it shows all the checkbox values in the second input of the div, if I click again on "Add New" he starts to put the values in the input of the third div ...

It's complicated to explain, I do not know if I'm being clear, but put the example in jsbin [jsbin.com ] .

See:

Click the "Add New" only once and then click the checkbox. Then click "Add New" again and see that it stops working right.

I wish he would just show the values of the div corresponding checkbox.

Thanks and sorry my english.

daveVk

5:21 am on Aug 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You refer to $seletor within the onclick function, I do not think it is defined (correctly) at the time onclick executes, it is assigned without a var making it global ?, in any case it would be safer to compute it within the onclick function based on this.

Is there a reason for preceeding variable names with a $ ?

morehawes

11:32 am on Aug 12, 2010 (gmt 0)

10+ Year Member



Is there a reason for preceeding variable names with a $ ?


I haven't time to look into your problem properly now but I thought I would mention that I have seen the $variable convention recommended in some jQuery books. As $ is a valid character it does not cause any issues but some people think makes the code more readable as it helps identify variable names.