Display table row based on the selected option of Select html tag

Ismail

So I have tried to display the content of a table based on the country of a user. basically if a user selects the united states as option, he gets a table row containing US data displayed.. I used a select with options, and every option has the domain extension of country as a value ( for example, for Brazil option, the value is br : <option value="br">Brazil</option>, plus the table row for it has the same option value as an ID ( <tr id="br" style="display: none;">..</tr> )

Is there any script to display a country data once the user selects that country in the options ?

Thank you, and here's my code:

HTML:

<select id="data">
  <option value="#">Select a country ..</option>
  <option value="us">United States</option>
  <option value="es">Spain</option>
 <!-- more countries -->
</select>


<div id="container">

<table border="1">
 <tr>
  <td> Country </td>
  <td> Chance</td>
 </tr>
 <tr id="us"  style="display: none;">
  <td> United States </td>
  <td> 2.02 % </td>
 </tr>
 <tr id="es" style="display: none;">
  <td> Spain </td>
  <td> 2.12 % </td>
 </tr>
</table>

</div>

I tried the following:

Jquery:

$('#data').change(function() {
    $('tr#($(this).val())').css('display','block');
});

Regards,

Thank you!

taxicala

Thats not the way to concatenate, try this instead:

$('#data').change(function() {
    $('tr#' + $(this).val()).css('display','block');
});

EDIT with the OP comment:

Add a class to all the TRs that should hide/show, and then:

<table border="1">
 <tr>
  <td> Country </td>
  <td> Chance</td>
 </tr>
 <tr class="hideShowTr" id="us"  style="display: none;">
  <td> United States </td>
  <td> 2.02 % </td>
 </tr>
 <tr class="hideShowTr" id="es" style="display: none;">
  <td> Spain </td>
  <td> 2.12 % </td>
 </tr>
</table>

$('#data').change(function() {
    $('.hideShowTr').css('display','none');
    $('tr#' + $(this).val()).css('display','block');
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use html option tag and check which option is selected?

From Dev

Displaying selected option from database in a select option tag

From Dev

Select-option tag remains selected on refresh

From Dev

Select option selected an not selected

From Dev

HTML select option show list after first select option selected

From Dev

Display table rows based on selected option from drop down list using jquery

From Dev

If Select tag option is selected shows another select tag

From Dev

Struts <html:select> set selected option dynamically

From Dev

Ruby on rails: select_tag how to display based on selected value

From Dev

Change options in same select based on selected option

From Dev

php/pdo/mysql accessing selected row from a select * in html table

From Dev

Change select options based on another selected option

From Dev

how to display a generated select option based on its row in a dynamic select box

From Dev

make the <select> tag selected display HTML

From Dev

Displaying selected option from database in a select option tag

From Dev

Select-option tag remains selected on refresh

From Dev

HTML select option show list after first select option selected

From Dev

Android Display Selected Table Row in Dialog

From Dev

Display based on Option Selected

From Dev

Change color of selected option in html select input

From Dev

Select array based on which option is selected

From Dev

How to disable <select> option based on other <select> option selected?

From Dev

php/pdo/mysql accessing selected row from a select * in html table

From Dev

Display div based on option selected in javascript

From Dev

Sort a Table based on the option select

From Dev

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

From Dev

Display None on Select Option based on the data

From Dev

How do I display Text in HTML based on an option selected from a Drop-Down Menu?

From Dev

Select option comparing with Table Row

Related Related

  1. 1

    How to use html option tag and check which option is selected?

  2. 2

    Displaying selected option from database in a select option tag

  3. 3

    Select-option tag remains selected on refresh

  4. 4

    Select option selected an not selected

  5. 5

    HTML select option show list after first select option selected

  6. 6

    Display table rows based on selected option from drop down list using jquery

  7. 7

    If Select tag option is selected shows another select tag

  8. 8

    Struts <html:select> set selected option dynamically

  9. 9

    Ruby on rails: select_tag how to display based on selected value

  10. 10

    Change options in same select based on selected option

  11. 11

    php/pdo/mysql accessing selected row from a select * in html table

  12. 12

    Change select options based on another selected option

  13. 13

    how to display a generated select option based on its row in a dynamic select box

  14. 14

    make the <select> tag selected display HTML

  15. 15

    Displaying selected option from database in a select option tag

  16. 16

    Select-option tag remains selected on refresh

  17. 17

    HTML select option show list after first select option selected

  18. 18

    Android Display Selected Table Row in Dialog

  19. 19

    Display based on Option Selected

  20. 20

    Change color of selected option in html select input

  21. 21

    Select array based on which option is selected

  22. 22

    How to disable <select> option based on other <select> option selected?

  23. 23

    php/pdo/mysql accessing selected row from a select * in html table

  24. 24

    Display div based on option selected in javascript

  25. 25

    Sort a Table based on the option select

  26. 26

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

  27. 27

    Display None on Select Option based on the data

  28. 28

    How do I display Text in HTML based on an option selected from a Drop-Down Menu?

  29. 29

    Select option comparing with Table Row

HotTag

Archive