last day (14 days later) » 

2:38 AM
1
A: jquery button enable if checkbox and select option

GaelAt each check state change, verify what you want: if there at least one checkbox checked and if the "no action" checkbox is not checked. Then you can enable the submit button, or otherwise disable it. function updateSubmitButtonState(){ var enableableLineCount= 0; $("tr").each(fu...

 
thanks for the answer but last element is a select option not a checkbox. how to manage that?
 
I have updated the snippet.
 
i have updated my question with the snapshot and also with the structure of html. Since I am dynamically generating rows of the table, I am not thinking of using "id". Can we play without the "id"?
 
I tried to fit your example, but note that providing code may be more efficient.
As I understand, if there just one select which has an "no action" value, the submit button is disabled, is that right?
Because, you may be want that it is only if the select value of the checked line have a "no action" value which disable the submit button.
 
yes, so if each checkbox checked has selected option other than 'no action', i want to make the button visible else it will remain disabled. Also, button should be in disable mode after the page loading since all the checkboxes will be unchecked and "no action" would be the default option.
<script> var submitButt = $("input[type='submit']"); submitButt.attr("disabled","disabled"); function updateSubmitButtonState(){ var submitButt = $("input[type='submit']"); if( $("input[type='checkbox']:checked").length > 0 && $("select option[value='no-action']:selected").length == 0 ) submitButt.removeAttr("disabled"); else submitButt.attr("disabled","disabled"); } ..... This I have done to make button disable during page loading which is keeping button disabled throughout even on right combinations. Is this the wrong way?
 
2:38 AM
It is the wrong way if it is not what you want to achieve :)
see the update, you need to check all your table at each change. A better way could be to store the state of each line to know after eache change if there is always a line which can enable the submit button
 
thanks Gael, worked!!!
One query gael
you are checking each row and if the row has checked checkbox and select option other than "no_action" then activate the button
but what if the user on the second row, just checks the checkbox and leaves the option as "no-action", then also the button will be activated - which would be a wrong submit
 
In my example, no-action is not the default. But whatever, if the value of the select is no-action, so the line will not be able to activate the button.
I activate the button if there at least one line which have the checkbox checked AND the select with another value than no-action
 
but once the button is activated, even if the action chosen is no-action, there is no way to disable the button.
for the other row.
 
if the is button is activated and there is a change on select or on checkbox, all the table is completly parsed. If there is a line which allow the button to be enabled, it will be enabled, otherwise, it will be disabled, regardless to its current state.
 
I understand that but don't think that is a flaw. Supposedly, if row 1 has activated the button and if i check the checkbox for row2 but the action for row 2 is "no-action", button will still be enabled. Is there any way that I can manage that all the rows must be in proper way (checked checkbox & option other than 'no-action') before enabling the button?
Sorry for all the changes but I have just started with jquery and not able to do thing easily.
 
3:22 AM
I though it was the behavior you wanted.
I'm going to change that!
So, if there only one line which have the select on no-option and which have the checkbox checked, the button will be disabled?
 
3:41 AM
Can you check that: jsfiddle.net/gael/5krycrxg ?
 
3:51 AM
I think this will do the job.. thanks a lot Gael
 
you're welcome !
 

last day (14 days later) »