M
M
Maxim Medvedev2010-09-11 20:52:35
JavaScript
Maxim Medvedev, 2010-09-11 20:52:35

Selecting the first checkbox?

There is this code:

&lt;_tr class=&quot;table_rows&quot;&gt;<br/>
<br/>
&lt;_td&gt;&lt;_input name=&quot;del[{$item-&gt;id}]&quot; type=&quot;checkbox&quot; id=&quot;del[{$item-&gt;id}]&quot; value=&quot;1&quot;&gt;


<_td>
<_input name="test" type="text" id="test" value="123" size="60">
<_/td>

<_td>
text
<_/td>
<_/ tr>


The code above is used to display a list of documents, when you click on them line by line, the checkbox should be highlighted. The problem is that when clicking on other checkboxes, links or input fields, the first checkbox is highlighted. How to make a restriction?

$('.table_rows').click(function() {<br/>
 $(this).toggleClass(&quot;selects&quot;);<br/>
<br/>
if( $(this).find(&quot;input&quot;).is(&quot;:checked&quot;))<br/>
 {<br/>
 $(this).find(&quot;input&quot;).removeAttr(&quot;checked&quot;);<br/>
 } else {<br/>
 $(this).find(&quot;input&quot;).attr(&quot;checked&quot;,&quot;checked&quot;);<br/>
 }<br/>
 <br/>
 }); <br/>

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
mishunika, 2010-09-11
@mishunika

Maybe you forgot to post?
Something I didn't understand your question.

M
mishunika, 2010-09-11
@mishunika

<_input type="checkbox" id="yourID" value="1"/>
your text

M
mishunika, 2010-09-11
@mishunika

sorry for this gibberish. I just forget that html tags work here. And so, the final answer is:
<_input type="checkbox" id="your_ID" value="1"/>
<_label for="your_ID">your text for your checkbox<_/label>

L
lashtal, 2010-09-11
@lashtal

I don't understand the question, but will any of this work? )
jsfiddle.net/4k6PA/7/

S
Sererator, 2010-09-11
@Serator

Events in jquery are fired during the bubbling (except for the focus event and possibly others for certain browsers, since IE doesn't support "capture" in its <9 version).
Based on this, you can activate the checkbox during the click on the line and a second time if the event pops up before the link / text field.
Well, delegating makes sense to hang such an event on the entire table. And next time, format your question normally, as well as learn js, because there is nothing complicated / interesting in the sim :).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question