how and where can i set a default value in a selcted box from a SESSION variable

how and where can i set a default value in a selcted box from a SESSION variable

zerennerzerenner Posts: 16Questions: 6Answers: 0

Hello,

I have 2 selected boxes in the datatable. These are filled from the database of 3 tables. These are users, departments and message. Via a join (user ID in the table user = $ _SESSION ['USER_ID] -> department ID -> department ID of the table area -> department name) I let the message select the department name. How and where can I use the variable $ _SESSION ['AREA_ID'] to pass the corresponding value as default value, so when preselecting new data records or when editing the area of ​​the user I preselected ?.

After a long search and trying different examples I have not yet found the right solution.

Since I have no public website attached the code message controller (Ajax query) and messages (output of the table).

Enclosed the code in the files and a screenshot. The user has the area ID 15 = EDV, which is why this is selected.

Thanks for any help. I hope my bad english and the problem is understandable.

Sorry for the bad english

Many Thanks
Dirk Zerenner

Answers

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    Hi Dirk,

    There are two options:

    1) Have the PHP generate the Javascript - that way you can do something like:

    <?php
    echo <<<EOD
    $(document).ready( function () {
      var editor = new $.fn.dataTable.Editor( {
        fields: [
          {
            def: {$_SESSION['USER_ID']},
            ...
    EOD;
    

    2) Ajax load the values you want for the defaults (using $.ajax() for example) and then use the field().def() method to set the default for the field.

    Allan

This discussion has been closed.