Question

apologies for question title not making too much sense.

I am trying to pass the checkbox from the current row to another function where that function checks if it is checked or not and performs accordingly.

I have a table with several rows, and when changing an input qty I want the current row and checkbox name/id to be passed to another function.

you can see the example here

The html in this fiddle is what is generated by my php page onload.

I can get the onchange to fire but the checkbox for that row is always unchecked. I think this is because var cb = $(this).siblings('input[name^="treated"]'); is not passing the correct object to the next function.

I did get some assistance from @pXL previously with this fiddle but whilst it works in this example, cant get it to work with my generated html.

so when changing qty, I want alert 1 to fire if the checkbox treated is checked for that specific row. if it is not checked then alert 2

Thanks in advance.

Was it helpful?

Solution

var cb = $(this).siblings('input[name^="treated"]');

supposed to be

var cb = $(this).closest('tr').find('input[name^="treated"]');

The siblings will not work in this case as input[name^=treated] is not a sibling of the quantity input.

Siblings are the elements are are present at the same level as the other elements.

But here the treated input in inside another td and not the same td

Check Fiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top