Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statement object check this.form 1

Status
Not open for further replies.

seanybravo

IS-IT--Management
Sep 24, 2003
89
GB
I want to check what form element (listboxes) is being passed to this function and I have a list of numbers that have to be dealt with differently in a sort, but I am having trouble with the If statement because I seam to be passing an object. I think that it is because I am using the this shortcut.

Any help would be appreciated

Thanks

Code:
function moveOptions(theSelFrom, theSelTo)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  
  if(NS4) history.go(0);
	
//Problem Here !!!!!!
//This is where I am trying to check what listbox is being passed	
	if (theSelTo == document.form['CustomerDetails'].elements['SelectedEmployees'] || theSelTo == 'Employees'){
	alert("employees")
	sortOptionsN(theSelTo)
	}	
}

This is the call to it.
Code:
onclick="moveOptions(this.form.SelectedEmployees,this.form.Employees)"
 
Where are you calling the "onclick" from? If an option or select element, then you should change "onclick" to be "onchange".

To remove all items from a select element, there's no need to loop round - you do this simply in one line:

Code:
selObj.options.length = 0;

In fact, for lots of helpful advice on dyunamic listboxes, check out my FAQ, "How do I create multi-level select / list / drop down boxes?" (faq216-6294).

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for your help. My lists work fine. I am just having problems with If statement syntax when I check what form list is passed. The onclick is being called from a button as i am creatin a pick list.

Thanks

Sean
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top