Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help on Jquery/Select Option

Posted on 2012-03-21
6
Medium Priority
?
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

618 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