• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

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>
0
REA_ANDREW
Asked:
REA_ANDREW
  • 5
  • 3
  • 2
  • +1
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now