JavaScript jQuery trying to get value of one select option based on result of another select option

have the below Javascript already, and a couple of Select Groups.

When selecting one of the options in one of the groups, it fills the relavent text box with the text() of that option, and the single ID text box with the val(). This all works fine.

but where I am stuck is that , I need to have it , so that when I select an option in one of the select groups, it looks up the option with the same value in the other select group, and then displays the text of that option in the relevant box.

e.g. If I pick 'Option1', it displays 'Option1' in the first text box, and 'item1' in the second text box (and 1 in the ID text box). If I pick 'item3', it displays 'item3' in the second text box, and 'option3' in the first text box (and 3 in the ID text box).

I got as far as using:

var disp = $('#selItem').find('option[value=1]').text();
alert(disp);

but can't get the dynamic value to go with 'option[value=1]'.

I tried:

var thisValue = $('#txtID').val( $(this).val() ); 
alert(thisValue);

but it responds with [object Object].

If anyone can point me in the right direction it would be appreciated.

<html>
<head>
    <script language="JavaScript" src="../Generic/JAVASCRIPT/jquery.js" type="text/javascript"></script>
    <style>
        .InputField{ width:150px;}
    </style>
    <script>
        $(document).ready( function() 
        {
            $('#selOption').change( function() 
                {
                    $('#txtID').val( $(this).val() );
                    $('#txtOption').val($('#selOption option:selected').html());
                }
            );

            $('#selItem').change( function() 
                {
                    $('#txtID').val( $(this).val() );
                    $('#txtItem').val($('#selItem option:selected').html());
                }
            );
        })  
    </script>
</head>


<body>
    <select id="selOption" class="InputField">
        <option value="" disabled="" selected="" style="display:none;">Select One...</option>
        <option value="1">Option1</option>
        <option value="2">Option2</option>
        <option value="3">Option3</option>                      
    </select>

    <select id="selItem" class="InputField">
        <option value="" disabled="" selected="" style="display:none;">Select One...</option>
        <option value="1">item1</option>
        <option value="2">item2</option>
        <option value="3">item3</option>                        
    </select>

    </br>

    <input type="text" name="txtOption" id="txtOption" placeholder="Which Option is it?" class="InputField"/>
    <input type="text" name="txtItem" id="txtItem" placeholder="Which item is it?" class="InputField"/>

    </br></br>

    <input type="text" name="txtID" id="txtID" placeholder="ID Number" class="InputField"/>
</body>
</html>
Answer:1

It's just:

var thisValue = $(this).val();

When you call .val() with an argument, as in:

var thisValue = $("#txtID").val($(this).val());

it doesn't return the value, it returns the jQuery object, to allow for chaining.

To use this to get the text of the other select, do:

var itemText = $("#selItem option[value=" + thisValue + "]").text();
Answer:2

This is totally normal behavior that it returns Object. This is natural jQuery chaining, so You could use something like $(this).val(something).hide();

Please note that $(selector).val('something') sets up value of selected object and returns that object. If You would like to get value, You have to use val() without argument.

Answer:3

Example placed here http://jsfiddle.net/aS87B/3/ Here are 3 input fields First input<br> <td class='exchange_rate1'> <input type="text" name="exchange_rate1" id='exchange_rate1' class=...

Example placed here http://jsfiddle.net/aS87B/3/ Here are 3 input fields First input<br> <td class='exchange_rate1'> <input type="text" name="exchange_rate1" id='exchange_rate1' class=...

  1. jquery input value change
  2. jquery input value set
  3. jquery input value change event
  4. jquery input value length
  5. jquery input value by name
  6. jquery input value empty
  7. jquery input value get
  8. jquery input value undefined
  9. jquery input value change listener
  10. jquery input value not updating
  11. jquery input value append
  12. jquery input value selector
  13. jquery input value clear
  14. jquery input value empty check
  15. jquery input value array
  16. jquery input value validation
  17. jquery input value update
  18. jquery input value not showing
  19. jquery input value remove
  20. jquery input value increment

I have cloned div duplicate elements in body with the class name "combo". I need to remove all duplicates except the original div element

I have cloned div duplicate elements in body with the class name "combo". I need to remove all duplicates except the original div element

  1. remove duplicate elements from array
  2. remove duplicate elements from list python
  3. remove duplicate elements from list
  4. remove duplicate elements from list java
  5. remove duplicate elements from array java
  6. remove duplicate elements from array javascript
  7. remove duplicate elements from sorted array
  8. remove duplicate elements from array c++
  9. remove duplicate elements from sorted linked list
  10. remove duplicate elements from unsorted array
  11. remove duplicate elements from array js
  12. remove duplicate elements from array python
  13. remove duplicate elements from vector c++
  14. remove duplicate elements from array ruby
  15. remove duplicate elements from array bash
  16. remove duplicate elements from linked list
  17. remove duplicate elements from array in php
  18. remove duplicate elements from string in java
  19. remove duplicate elements from string in python
  20. remove duplicate elements from linked list in python

I would like when adding "invoice" in my application could look the customer in the database, so I do not have to enter the entire name instead of just to a select input was where I would have taken ...

I would like when adding "invoice" in my application could look the customer in the database, so I do not have to enter the entire name instead of just to a select input was where I would have taken ...

  1. download database from server
  2. database download
  3. downloading file from database in java
  4. downloading files from database php
  5. downloading files from database
  6. downloading database tutorial
  7. download database template
  8. download sql database
  9. downloading files from mysql database

Everything works fine except one thing, I'd like it so when you have the .show class already visible, it will fade again when you click on another of the #c- divs. http://jsfiddle.net/7KdR6/1/ $('[...

Everything works fine except one thing, I'd like it so when you have the .show class already visible, it will fade again when you click on another of the #c- divs. http://jsfiddle.net/7KdR6/1/ $('[...

  1. jquery each fadein