473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Swap values of Drop Down List

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. 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.
Expand|Select|Wrap|Line Numbers
  1. <select id="order_of_display" name="order[display]" >
  2. <% @orderNumber= item.position %>
  3. <%for i in (1..@items[:active].size) %>
  4. <%if( i == @orderNumber) %>
  5. <option value="<%= item.id %> " selected="selected"><%= i%></option>
  6. <%else%>
  7. <option value="<%= item.id %>"><%= i%></option>
  8. <%end%>
  9. <%end%>
  10. </select>
  11.  
Apr 8 '13 #1
3 1944
r035198x
13,262 8TB
Post the javascript code that you tried and explain where you are stuck with it.
Apr 8 '13 #2
Below is the ruby code and javascript. On mouse up, i am getting the existing selected text value. On change, the other selected text value. I want the existing text value inside changeOrder function. Where am i wrong?Please correct me.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var currentVal;
  3. function getCurrentVal(selectItem)
  4. {
  5. currentVal=selectItem.options[selectItem.selectedIndex].text;
  6. return currentVal;
  7. }
  8. function changeOrder(sel)
  9. {
  10. alert(getCurrentVal());
  11. posval = sel.options[sel.selectedIndex].text;
  12.  
  13. }
  14. </script>
  15. <select id="order_of_display" name="order[display]" onmouseup="getCurrentVal(this);"  onchange="changeOrder(this);">
  16. <% @orderNumber= item.position %>
  17. <%for i in (1..@items[:active].size) %>
  18. <%if( i == @orderNumber) %>
  19. <option value="<%= item.id %> " selected="selected"><%= i%></option>
  20. <%else%>
  21. <option value="<%= item.id %>"><%= i%></option>
  22. <%end%>
  23. <%end%>
  24. </select>
  25.  
Apr 8 '13 #3
r035198x
13,262 8TB
Do a test without the ruby, just hard coding some select option values and get it to work like that. If it does work and the ruby is the problem then ask in a ruby forum.
Apr 9 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: R-D-C | last post by:
Hi, got a drop-down list on a windows form in VS.NET2003. In the form load when NOT a postback, we add four values to the drop-down list. These appear in Internet Explorer. When you click...
3
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
7
by: Miguel Dias Moura | last post by:
Hello, i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR. I don't want...
1
by: inbamca | last post by:
Hi, Functionality is like when pressing 'CTRL+click' on drop down list in the main jsp page, a popup window appears with a list box contains all the values of the drop down clicked on the main page....
3
by: Brad Isaacs | last post by:
ASP.NET 2.0 / SQL Server 2000 db / Visual Basic Code behind On my .aspx page I have added an SQL Datasource that contains the SQL query to retrieve the list for my Drop Down List Box. Using...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
2
by: Doug | last post by:
Hi, I can't figure out how to create a drop-down list box. The help file says it exists. The icon in the help file matches the combobox in the toolbox. I tried using a combox box, both with and...
3
by: jcassan | last post by:
Hello folks. I am new to these forums and have something, which has been stumping me for little while. I am using pspell to spellcheck a scrolling textbox (textarea) containing user input. I...
1
by: chandhseke | last post by:
Hi Folks, I have designed a dynamic drop down list but having problems since it is not working as intended. Please help <html> <head> <Script language="Javascript"> var Select = new...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.