473,383 Members | 1,795 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,383 software developers and data experts.

Arranging/swapping drop down box values

Hello All,
I am having the drop down list with count 1 to 10 which is looped for itemlist. For item 1 dropdown list shows count 1 to 10,item 2 also dropdown list shows count 1 to 10 and so on. I want to preset the value for the drop down list which should display on page load like for item 1 drop down value count set to 1, for item 2 drop down value count set 2.. and so on. How can i acheive this please let me know. Code is attached for the drop down list. Want the solution in html/javascript/ruby on rails.
Expand|Select|Wrap|Line Numbers
  1.     <select id="order_of_display" name="order[display]">
  2.                                                     <option value="0" selected ="selected">Selectorder</option>
  3.  <% if  @items[:active] %>
  4.                                                     <%for i in (1..@items[:active].size) %>
  5.                                                          <option value=" <%= i  %>" > <%= item.id %> </option>
  6.                                                          <% end %>
  7.                                                           <% end %>
  8.                                                   </select>
  9.  
Apr 2 '13 #1
3 1752
acoder
16,027 Expert Mod 8TB
You would probably be best setting this in Ruby/Rails.

You've already set the selected option value:
Expand|Select|Wrap|Line Numbers
  1. selected ="selected"
Add this to the desired option value setting for each drop down.

If you still need this done in JavaScript, let us know.
Apr 2 '13 #2
Hello,
I am able to view the selected one. Now my problem is i want to swap the drop down values on change. For example
drop down 1 - value selected 1
drop down 2 - value selected 2 and so on. If i change drop down 1 to value 2 , drop down 2 value should change to 1 automatically(swapping). What should i do to achieve this?Please help.
Expand|Select|Wrap|Line Numbers
  1. <select id="order_of_display" name="order[display]" onchange="swap();">
  2.  
  3.                                             <% @orderNumber= item.position  %>
  4.                                             <%for i in (1..@items[:active].size) %>
  5.  
  6.                                             <%if( i == @orderNumber) %>
  7.  
  8.                                             <option value="<%= item.id %> " selected="selected"><%= i%>  </option>
  9.  
  10.                                             <%else%>
  11.                                             <option value="<%= item.id %>" ><%= i%> </option>
  12.              <%end%>
  13.  
  14.                                             <%end%>
  15.                                             </select>
Apr 4 '13 #3
acoder
16,027 Expert Mod 8TB
The idea is simple, e.g.
Expand|Select|Wrap|Line Numbers
  1. var val1 = dropdown1.value;
  2. dropdown1.value = dropdown2.value;
  3. dropdown2.value = val1;
Apr 6 '13 #4

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

Similar topics

2
by: Tom Petersen | last post by:
I have a drop down box where the choices are populated from a database query, this part works fine: <option value><% = strEmail %></option> I was wondering if it is possible to keep the value as...
6
by: PT | last post by:
I got a form with many text boxes, checkboxes and 3 drop downs. From that 3, 2 are dependant. I can choose one drop down, and the next drop down should display the dependant values of the first...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
5
by: Xarky | last post by:
Hi, I followed this link to design my drop-down menu: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_fp2003_ta/html/OfficeFrontPageCreateDropDownMenu.asp The css file being...
2
by: rishu banerjee | last post by:
hi all. I'm new to ASP. can anyone help me in getting values of a drop down to be displayed in a textarea.say if we have the drop down elements as color, flower,..etc. as we select color, it should...
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...
4
by: lisles | last post by:
i want to populate a drop down based on a selection from anoher drop down list. my drop down values are stored in a seperate page as shown below: //gazetted or non gazetted $isGazetted = array(...
1
selvasoft
by: selvasoft | last post by:
Hi Please any one help me i want list out the values in drop down box. But the values from my database. How can am select that value from my database using JSP.give me example code pleas.
0
by: jimgym1989 | last post by:
Hi there, I have 2 PHP files, memeber.php & view.php This is my member.php while($row = mysql_fetch_array($strSQL)){ $data .= "<tr>"; $data .= "<td>"; $data .= "<input type='checkbox'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.