Onchange function in datatables form

Onchange function in datatables form

ZulfahmiRadziZulfahmiRadzi Posts: 6Questions: 2Answers: 0

Hi, I'm working on this form where input2 will change according to input1. Both are select type input. The problem that I'm facing right now is the onchange function only working on the first row. Here is my progress so far. Will appreciate any help for this matter :)

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Hi @ZulfahmiRadzi ,

    The problem is because the ID for the first select is always input1 - IDs should be unique across the DOM. Because of this, it's only looking at the first instance, the first line.

    Cheers,

    Colin

  • ZulfahmiRadziZulfahmiRadzi Posts: 6Questions: 2Answers: 0

    Hi @colin,

    What if I load the table using ajax? How to make different ID for each row?

  • kthorngrenkthorngren Posts: 20,274Questions: 26Answers: 4,765
    Answer ✓

    You would use columns.render. Here is an example with buttons. Even though its not select inputs it should give you an idea of what to do. The key is to use the meta.row parameter to get the row id.

    Kevin

  • ZulfahmiRadziZulfahmiRadzi Posts: 6Questions: 2Answers: 0

    Problem solved. Thanks for the quick response!

This discussion has been closed.