Hello All,
I have list of DropDownList of items fetching from database, all have values of 1,2 and 3...

DropDownList1 has a selected value of 1

DropDownList2 has a selected value of 3

DropDownList3 has a selected value of 2

What I want is to swap values. It's urgent please help.

i.e. if I selected number 2 in DropDownList1, DropDownList3 should select 1 automatically.
Using Ruby on Rails to fetch the data from db, Ajax,Javascript & HTML

Member Avatar for LastMitch

I have list of DropDownList of items fetching from database, all have values of 1,2 and 3...

Do you have a query? Can post what your query looks like.

Thank you for your reply. As of now i am able to display the drop down list fetching the details from database which is selected. I am unable to find the swapping logic. I tried this code from this website
http://www.webdeveloper.com/forum/showthread.php?231117-Swap-values-of-DropDownList , no luck. I am looking for this exact functionality. Please help if i can get solution in js & ajax.
Below is the ruby code for fetching the details.

<select id="order_of_display" name="order[display]" >
<% @orderNumber= item.position  %>
<%for i in (1..@items[:active].size) %>
<%if( i == @orderNumber) %>
<option value="<%= item.id %> " selected="selected"><%= i%></option>
<%else%>
<option value="<%= item.id %>"><%= i%></option>
<%end%>
<%end%>
</select>

How can i get the current selected text value and changed text value in one javascript function? Please help.

Member Avatar for LastMitch

How can i get the current selected text value and changed text value in one javascript function? Please help.

You can used this (it's in jQuery):

http://gotochriswest.com/blog/2011/07/22/javascript-swap/

The link you provide is 3 years old.

The code is a bit hard to modify to fit your ruby code.

You need to find something similiar and more easily to modify.

I think the jQuery code might be more easier to modify than the code from your link.

How can i get the current selected text value and changed text value in one javascript function? Please help.

Thank you so much. But i dont know how to use Jquery in Javascript. If possible can i get the link of working sample with the same logic with full code so that it will be easy for me to modify. Otherwise is there any way to get the already selected text value and changed text value of drop down list in one javascript function?
Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.