5
Hello dear beasts in Jquery, following the logic of the example below, how to make select always return to the first value of the list after unchecking the respective checkbox?
And the second question is whether there is a better (simpler) way to get the same result.
I thought I had succeeded, through previous question but error appeared.
From now on, thank you.
tu é fera! Another question: Following this logic, how to add more "items" to the IF in this format? For example, how to add a "$('#id'). show();" on that line?
– Danilo Fagundes
@Danilofagundes Check out my code, in your version you are using too much (redundant) code and it is too customized. It is better to lie simple and use the DOM, ie: find which select is in the same
<tr>
and do not fetch the widget by ID.– Sergio
I understood, I get a little lost using this logic but for lack of knowledge (custom). For example: in this new line of code: if (!this.checked) select.prop('selectedIndex', 0); what about adding a new "item" in that same if ? a "$('#id'). show();" for example. Understanding this makes it easier for me to assemble others. Thank you ;)
– Danilo Fagundes
@Danilofagundes what do you mean by "new item"? do you want to change more than one select at a time?
– Sergio
Imagine a <span id="text1">, following your tip, how to hide span when selecting any of the "checkbox" and show span when there is no selection? So I believe I will understand how if and Else works in this code. Here’s the deal: https://jsfiddle.net/8uk440do/11/
– Danilo Fagundes
@Danilofagundes in this case the simplest is to check whether the sum is
>0
... is at least the most practical, so:$('#texto1').toggle(!sum);
: https://jsfiddle.net/8uk440do/12/ but you may also use.filter()
, which gives the same result: https://jsfiddle.net/8uk440do/13/– Sergio
Endendi, and what would be the alternative using the "checked" checkbox state? Then, I think it became clearer: https://jsfiddle.net/8uk440do/15/ ... I end here. Thanks so much for today’s lesson and sorry about anything, I’m a beginner here.
– Danilo Fagundes
@Danilofagundes https://jsfiddle.net/8uk440do/16/, I prefer not to use Ids. Have a look at the suggestion. If you don’t understand, ask a new question that you will receive help. I made some corrections to your example, but the key is
eq()
which chooses an element among the found ones, and receives thei
which is the index of inputs. So long as there is 1span.aviso
for each input this code works, regardless of the amount.– Sergio
perfect. Following his example I was able to include some actions in the function, the sum in parallel only of the selects, hide the subtotal if the respective selectbox is not selected, hide the total (if the sum is zero), https://jsfiddle.net/8uk440do/18/ worked perfectly, I’m going to open up a new question so that you can direct me to any part with redundancy in the code. Based on your previous answers, there probably is. Thanks for the help ;)
– Danilo Fagundes
Good morning Sergio. Basically what changes to the use of each() methodology in a structure of "Divs", without table structure, tfoot, tr... ? I am here trying to apply the last learning that you have passed me.
– Danilo Fagundes
@Danilofagundes have an example in jsFiddle of this structure?
– Sergio
Hello beast, following the logic you gave me and on the basis of trial and error I managed to make it work. I managed to include the bootstrap too, for me this is all new, so sorry if I sometimes ask too much. Follow the link of the model run without the table structure. https://jsfiddle.net/yne288ar/ I tried to optimize more but errors appeared. Thanks for the lessons Sergio
– Danilo Fagundes
@Good Danilofagundes! I see no mistakes, seems to me well at first glance.
– Sergio