Form Swapper

This is a discussion on "Form Swapper" within the JavaScript Forum section. This forum, and the thread "Form Swapper are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 2nd, 2007, 03:52
New Member
Join Date: Nov 2007
Location: sri lanka
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Form Swapper

i have added pick list (java script from web) into my asp.net web application to transfer items from one field to another via "back" and "forth" buttons. But the problem is when i add it to the right side it apper in alpherbatical order. But i want to add it one after the other.Pls help !

ref:http://www.javascriptkit.com/script/...picklist.shtml
Reply With Quote

  #2 (permalink)  
Old Nov 3rd, 2007, 03:32
Highly Reputable Member
Join Date: Sep 2007
Age: 15
Posts: 717
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Swapper

Here is what you do. Replace your current javascript with this:
Code: Select all
<script language="javascript">
<!--

// PickList script- By Sean Geraty (http://www.freewebs.com/sean_geraty/)
// Visit JavaScript Kit (http://www.javascriptkit.com) for this JavaScript and 100s more
// Please keep this notice intact

// Control flags for list selection and sort sequence
// Sequence is on option value (first 2 chars - can be stripped off in form processing)
// It is assumed that the select list is in sort sequence initially
var singleSelect = true;  // Allows an item to be selected once only
var sortSelect = true;  // Only effective if above flag set to true
var sortPick = true;  // Will order the picklist in sort sequence

// Initialise - invoked on load
function initIt() {
  var selectList = document.getElementById("SelectList");
  var selectOptions = selectList.options;
  var selectIndex = selectList.selectedIndex;
  var pickList = document.getElementById("PickList");
  var pickOptions = pickList.options;
  pickOptions[0] = null;  // Remove initial entry from picklist (was only used to set default width)
  if (!(selectIndex > -1)) {
    selectOptions[0].selected = true;  // Set first selected on load
    selectOptions[0].defaultSelected = true;  // In case of reset/reload
  }
  selectList.focus();  // Set focus on the selectlist
}

// Adds a selected item into the picklist
function addIt() {
  var selectList = document.getElementById("SelectList");
  var selectIndex = selectList.selectedIndex;
  var selectOptions = selectList.options;
  var pickList = document.getElementById("PickList");
  var pickOptions = pickList.options;
  var pickOLength = pickOptions.length;
  // An item must be selected
  while (selectIndex > -1) {
    pickOptions[pickOLength] = new Option(selectList[selectIndex].text);
    pickOptions[pickOLength].value = selectList[selectIndex].value;
    // If single selection, remove the item from the select list
    if (singleSelect) {
      selectOptions[selectIndex] = null;
    }
    selectIndex = selectList.selectedIndex;
    pickOLength = pickOptions.length;
  }
  selectOptions[0].selected = true;
}

// Deletes an item from the picklist
function delIt() {
  var selectList = document.getElementById("SelectList");
  var selectOptions = selectList.options;
  var selectOLength = selectOptions.length;
  var pickList = document.getElementById("PickList");
  var pickIndex = pickList.selectedIndex;
  var pickOptions = pickList.options;
  while (pickIndex > -1) {
    // If single selection, replace the item in the select list
    if (singleSelect) {
      selectOptions[selectOLength] = new Option(pickList[pickIndex].text);
      selectOptions[selectOLength].value = pickList[pickIndex].value;
    }
    pickOptions[pickIndex] = null;
    pickIndex = pickList.selectedIndex;
    selectOLength = selectOptions.length;
  }
}

// Selection - invoked on submit
function selIt(btn) {
  var pickList = document.getElementById("PickList");
  var pickOptions = pickList.options;
  var pickOLength = pickOptions.length;
  if (pickOLength < 1) {
    alert("No Selections in the Picklist\nPlease Select using the [->] button");
    return false;
  }
  for (var i = 0; i < pickOLength; i++) {
    pickOptions[i].selected = true;
  }
  return true;
}

//-->
</script>
As you may have noticed, I removed the bit that sorts the items. In other words, no matter how the items are selected and moved from left to right and vice versa, they will appear in the order that you moved them. If this is not what you wanted, then I must have misunderstood something, so please correct me.

Cheers,
SWagner
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)

Last edited by Stuart; Nov 3rd, 2007 at 03:42.
Reply With Quote
  #3 (permalink)  
Old Nov 5th, 2007, 04:43
New Member
Join Date: Nov 2007
Location: sri lanka
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Swapper

Thnx swagner . I found another also(http://weblogs.asp.net/coltk/archive...15/412657.aspx).
Now its working properly. but the problem is i cant move up and down the right side list to select items when i want. Do u have any idea?

Last edited by kabp321; Nov 5th, 2007 at 04:46.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding / Showing form fields based on previous form input John Alexander Hopper PHP Forum 1 Mar 10th, 2008 11:30
form variable within an iframe component of a form kissfreaque PHP Forum 3 Feb 29th, 2008 13:06
form variable within an iframe component of a form kissfreaque JavaScript Forum 5 Feb 29th, 2008 11:57
[SOLVED] PHP contact form redirect to same form Posie PHP Forum 14 Jan 29th, 2008 20:28
ASP form to check weather a form value is already in the database Andrew1986 Classic ASP 3 Oct 25th, 2007 08:23


All times are GMT. The time now is 04:49.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43