Solved

Help on Jquery/Select Option

Posted on 2012-03-21
6
274 Views
Last Modified: 2012-06-21
I need help on this.

I have 2 select options and the users can transfer messages from one box to another. I need to

Prevent User to transfer  - "Special Message*" (splMsg) to "Available Fields"
Prevent User to mix and combine all messages with "Special Message" under "Selected Fields" to "Available Fields" (user can combine all messages on "Selected Field" and can transfer to "Available Fields" but cannot move "Special Message"
      

Code is given below. Ignore my styles for now.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style>
        .row
        {
            width: 800px;
            background-color: Gray;
        }      
        .fieldsTable
        {
            float: left;
            width: 200px;            
        }
         .fieldsTableArrows
        {
            float: left;
            width: 100px;            
        }
    </style>
</head>
<body>
    <form>
    <div class="row">
       
        <div class="fieldsTable">
            <label>Available Fields:</label><br />
            <select id="availMsg" name="availMsg"  multiple="multiple" class="transferList"  size="5">
                <option value="msg01">Left Message 01</option>
                <option value="msg02">Left Message 02</option>
                <option value="msg03">Left Message 03</option>
                <option value="msg04">Left Message 04</option>
                <option value="msg05">Left Message 05</option>
            </select>
        </div>
        <div class="fieldsTableArrows">
            <input type="button" id="moveLeft" value="&gt;&gt;">
            <input type="button" class="moveRight" id="moveRight" value="&lt;&lt;">
        </div>
        <div class="fieldsTable">
            <label>Selected Fields:</label><br />
            <select id="selMsg" name="selectedFields" class="transferList" multiple="multiple"  size="5">
                <option value="msg11">Right Message 01</option>
                <option value="msg12">Right Message 02</option>
                <option value="msg13">Right Message 03</option>
                <option value="msg14">Right Message 04</option>
                <option value="splMsg">Special Message*</option>
            </select>
        </div>
    </div>
    </form>
</body>
</html>

<script type="text/javascript" language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>

<script type="text/javascript" language="javascript">
    $(function() {
        $('#moveLeft').click(function() {
            return !$('#availMsg option:selected').remove().appendTo('#selMsg').blur();
        });
        $('#moveRight').click(function() {
            $('#selMsg option:selected').remove().appendTo('#availMsg');            
            $('#selMsg').blur();
            return false;
        });
    });
</script>
0
Comment
Question by:mahaq
  • 3
  • 3
6 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37751063
http://api.jquery.com/filter/

for example
$('#moveRight').click(function() {
  $('#selMsg option:selected').filter(function(index) {
      return $(this).val() != "splMsg";
   }).remove().appendTo('#availMsg');            
  $('#selMsg').blur();
  return false;
 });

Open in new window

0
 

Author Comment

by:mahaq
ID: 37755757
Dear "mplungjan",

Many thanks on this quick reply and possibly the solution. I need little help on alerting the user not to mix and match the "splMsg" with all other messages while transfering from Right to Left. Also I need another alert when user tries to transfer "splMsg" too. Well I just need to alert & later on use a message key.

If you can provide a solution on these, I shall accept it in complete. Thanks in advance.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 37755976
You mean
$('#moveRight').click(function() {
  $('#selMsg option:selected').filter(function(index) {
      if ($(this).val() == "splMsg") {
        alert('Please do not transfer '+$(this).text());
        return false;
      }
      return $(this).val() != "splMsg";
   }).remove().appendTo('#availMsg');            
  $('#selMsg').blur();
  return false;
 });

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Closing Comment

by:mahaq
ID: 37760817
Dear "mplungjan",

Many thanks for helping me out on this.
I am bothering you one last time, can you please give me an alternate way, when users select  combination of any or all messages with splMsg, then transfer be not performed and force user to only select other than splMsg. I mean I need another alert (telling users to deselect splMsg and try again), but no change to your current logic, becoz it works for me.

Thank you so much.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37760856
Sounds very complicated to have an option not selectable
What exactly do you gave that makes you want to force these issues in the user?
0
 

Author Comment

by:mahaq
ID: 37760910
Never mind, I'll stick to the last solution. Thanks again.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
javascript comparing two dates 3 19
How to convert from xls to xlsx using java 7 40
where is team.js? 3 26
Not allowed to load local recource. 4 13
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question