Select an option from a dropdown list by onClick on data-table row

M.Izzat

I have a data-table when user click on the table row it will get the {{ content.id }} and pop up another child table.

    <table id="project-content-datatable" class="display table table-hover table-responsive" style="width: 100%">
    <thead>
    <tr>
        <th class="small text-muted text-uppercase"><strong>ID</strong></th>
        <th class="small text-muted text-uppercase"><strong>Name</strong></th>
        <th class="small text-muted text-uppercase"><strong>Description</strong></th>
    </tr>
    </thead>
    <tbody>
    {% for content in content_list %}
        {% if content.search_type.name == searchtype.name %}
            <tr class="text-primary">
                <td class="text-left" style="cursor: pointer"
                    onclick='load_workorder({{ content.id }});'>
                    {{ content.id }}
                </td>
                <td class="text-left" style="cursor: pointer" onclick='load_workorder({{ content.id }});'>
                    {{ content.name }} </td>
                <td class="text-left"> {{ content.description }} </td>
            </tr>
        {% endif %}
    {% endfor content_list %}
    </tbody>

<script>
    function load_workorder(content_id) {
    workorder_path = "/dashboard/workorder_list/" + content_id + "/?format=json";
    workorder_table.api().ajax.url(workorder_path).load();
</script>

Inside the child table I have a button to pop up a modal form to create a new content in it, one of its field is a dropdown ForeignKey field.

<div class="modal-body">
<div class="field">
<label>Project Type</label>
<select name="parent_project_content" required="" id="id_parent_project_content">
      <option value="">---------</option>

      <option value="1" selected="">Iron man suit</option>

      <option value="2">SEQ 001</option>

      <option value="4">SEQ 002</option>

    </select>
</div>

The <option> value is equal to the {{ content.id }}.I want to hide this field from user so how can I change the <option> to selected based on the {{ content.id }} click by user.

Any help is much appreaciated, Thanks

partypete25

So if the content.id value matches that of the option in the select dropdown the jQuery for that is pretty straightforward.

Here's a little example but all you need to do is call the selectOption() function and pass through your content.id value:

// my simplified example to grab a value from the table 
$('td').click(function(){
  var value = $(this).text();
  selectOption(value);
});

// pass the value to this function
function selectOption(v){
  $('#id_parent_project_content option[value="'+v+'"]').prop('selected', true);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get the string, but not the value from dropdown list option select

From Dev

Insert a "Select Value" option in dropdown list from array using jQuery

From Dev

Get the string, but not the value from dropdown list option select

From Dev

Populating a dropdown list from data table

From Dev

List is populated into a dropdown, by selecting an option of other dropdown, but the complete column gets that row's options in a table

From Dev

Select option in dynamically generated select (dropdown) list

From Dev

Select option comparing with Table Row

From Dev

Select a row from html table and send values onclick of a button

From Dev

Select a row (highlight) from html table and send values onclick of a button

From Dev

Select a row (highlight) from html table and send values onclick of a button

From Dev

jQuery select data from row onChange to option menu

From Java

How to select an option from dropdown select

From Dev

Dropdown select option pagination in ng-table

From Dev

Dropdown select option to filter a Django list

From Dev

"Select All" option for two or more dropdown list

From Dev

Javascript to select option in dropdown list with VALUE

From Dev

How to scrape data from website when dropdown list select?

From Dev

pre-select value in dropdown list from mysql data

From Dev

Inserting Dropdown list option in Table Cell

From Dev

AngularJS: Multiple list select option from same data

From Dev

On successful ajax, create a dropdown select from another table with preselected option value

From Dev

Select and display value from each new "select option" created for table row

From Dev

mysql select values from three dropdown option list and insert in one cell one value dd/mm/yyyy

From Dev

How to choose mysqli table id number from dropdown menu and output select values from that row

From Dev

Dropdown list only appears in the first table row

From Dev

from data table, randomly select one row per group

From Java

Using data.table to select rows by distance from another row

From Dev

Select row from data.table with min value

From Dev

Select a row from data table to show radio button value

Related Related

  1. 1

    Get the string, but not the value from dropdown list option select

  2. 2

    Insert a "Select Value" option in dropdown list from array using jQuery

  3. 3

    Get the string, but not the value from dropdown list option select

  4. 4

    Populating a dropdown list from data table

  5. 5

    List is populated into a dropdown, by selecting an option of other dropdown, but the complete column gets that row's options in a table

  6. 6

    Select option in dynamically generated select (dropdown) list

  7. 7

    Select option comparing with Table Row

  8. 8

    Select a row from html table and send values onclick of a button

  9. 9

    Select a row (highlight) from html table and send values onclick of a button

  10. 10

    Select a row (highlight) from html table and send values onclick of a button

  11. 11

    jQuery select data from row onChange to option menu

  12. 12

    How to select an option from dropdown select

  13. 13

    Dropdown select option pagination in ng-table

  14. 14

    Dropdown select option to filter a Django list

  15. 15

    "Select All" option for two or more dropdown list

  16. 16

    Javascript to select option in dropdown list with VALUE

  17. 17

    How to scrape data from website when dropdown list select?

  18. 18

    pre-select value in dropdown list from mysql data

  19. 19

    Inserting Dropdown list option in Table Cell

  20. 20

    AngularJS: Multiple list select option from same data

  21. 21

    On successful ajax, create a dropdown select from another table with preselected option value

  22. 22

    Select and display value from each new "select option" created for table row

  23. 23

    mysql select values from three dropdown option list and insert in one cell one value dd/mm/yyyy

  24. 24

    How to choose mysqli table id number from dropdown menu and output select values from that row

  25. 25

    Dropdown list only appears in the first table row

  26. 26

    from data table, randomly select one row per group

  27. 27

    Using data.table to select rows by distance from another row

  28. 28

    Select row from data.table with min value

  29. 29

    Select a row from data table to show radio button value

HotTag

Archive