Expected Identifier

Hi, I have a script which re-orders and moves options from one select box to another.

the first script is moveToList, which I got from quirksmode

the second which re-orders the options, I got from Experts-Exchange which mplunjan wrote.

Separately they work, but putting them together cause an error. Here is the whole html script, if you paste it in you will see what I mean and hopefully someone can give me an idea of how to solve this.

Thanks in advance.

Andrew

<html>
<head>
     <title>Reorder script</title>
<script>

function copyToList(from,to)
{
  fromList = eval('document.forms[0].' + from);
  toList = eval('document.forms[0].' + to);
  if (toList.options.length > 0 && toList.options[0].value == 'temp')
  {
    toList.options.length = 0;
  }
  var sel = false;
  for (i=0;i<fromList.options.length;i++)
  {
    var current = fromList.options[i];
    if (current.selected)
    {
      sel = true;
      if (current.value == 'temp')
      {
        alert ('You cannot move this text!');
        return;
      }
      txt = current.text;
      val = current.value;
      toList.options[toList.length] = new Option(txt,val);
      fromList.options[i] = null;
      i--;
    }
  }
  if (!sel) alert ('You haven\'t selected any options!');
}

/* Reorder script<BR>   Copyright (c) 2002 Michel Plungjan "michel at irt.org"
*/

function opt(txt,val,sel) {
   this.txt=txt;
   this.val=val;
   this.sel=sel;
   
}
function move(list,to) {    
    var total=list.options.length;
    index = list.selectedIndex;
    if (index == -1) return false;
    if (to == +1 && index == total-1) return false;
    if (to == -1 && index == 0) return false;
    to = index+to;
    var opts = new Array();
    for (i=0; i<total; i++) {
      opts[i]=new opt(list.options[i].text,list.options[i].value,list.options[i].selected);
    }
    tempOpt = opts[to];
    opts[to] = opts[index];
    opts[index] = tempOpt
    list.options.length=0; // clear

    for (i=0;i<opts.length;i++) {
       list.options[i] = new Option(opts[i].txt,opts[i].val);
       list.options[i].selected = opts[i].sel;
    }
    list.focus();
}
</script>  
</head>

<body>

<form name="form1" action="...">
<select MULTIPLE name="sel">
<option value="zero">0</option>
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
</select>
<input type="button" onClick="move(this.form.sel,-1);" value="/\">
<input type="button" onClick="move(this.form.sel,+1);" value="\/">
<input type="button" onClick="copyToList(sel,sel2);" value=">">
<input type="button" onClick="copyToList(sel2,sel);" value="<">
<select MULTIPLE name="sel2">

</select>
<input type="submit">
</form>


</body>
</html>
LVL 20
REA_ANDREWAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RoonaanCommented:
Try:

<input type="button" onClick="copyToList(this.form.sel,this.form.sel2);" value=">">
<input type="button" onClick="copyToList(this.form.sel2,this.form.sel);" value="<">

-r-
0
REA_ANDREWAuthor Commented:
Roonaan,

I still get the same error. At the top of the script It uses the Eval function, to resolve the form object.

  fromList = eval('document.forms[0].' + from);
  toList = eval('document.forms[0].' + to);
0
REA_ANDREWAuthor Commented:
I have checked and I cannot find any common calls that may be messing it up. Strange.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

RoonaanCommented:
Yes, sorry, I had to mention you could change your function to also:

function copyToList(fromList,toList)

-r-
0
smaccariCommented:
I would just have changed this:

<input type="button" onClick="copyToList('sel','sel2');" value=">">
<input type="button" onClick="copyToList('sel2','sel');" value="<">
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
smaccariCommented:
(placing quotes on sel and sel2 in the function call, that should be enough for your code to work)
0
REA_ANDREWAuthor Commented:
smaccari

cheers, missed that one lol.

this works now 75%, although if you paste it in and try it you will see that it does not allow the transfer from right to left.

This functionality is available when the script is on its own, but it is not working in this page when I conbine it with the re-ordering script.
0
KennyTMCommented:
You should quote it

<input type="button" onClick="copyToList('sel','sel2');" value="&gt;">
<input type="button" onClick="copyToList('sel2','sel');" value="&lt;">
0
REA_ANDREWAuthor Commented:
KennyTM

Cheers, in my previous post I have explained that, that is fixed now but still I cannot transfer options from Right To Left.  Although putting the script on its own, enables this functionality.

if you paste the code and run it you will see what I mean,

Thanks very much for your time by the way

Andrew
0
KennyTMCommented:
(well I think I was a bit slow; anyway the script works for me, in IE, Fx & Opera)
0
smaccariCommented:
The transfer works for me in both directions..
0
REA_ANDREWAuthor Commented:
thanks everyone.  

smaccari
 hit the nail on the head first, and I think you all agree that derserves the points.

I will wait for a bi, if anyone does not agree with me there, other wise I will Accept

smaccari

Answer

BUT thankyou all very much for your time on this problem also.

Cheers guys

Andrew (Will accept it in 15 mins)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.