syntax error "missing ; before statement"

  • Follow


I am getting the syntax error message "missing ; before statement" on
the line with the asterisks.
I thought maybe it was because the wave is a number 0-9 beginning the
select object?  I really don't know.  The data type for wave is text.

This is a search form with 5 fields and 4 related value lists.
The first 2 are wave and bu.
This is a work around script for IE 7 and AJAX cascading drop down
lists using a hidden hard wired option list of wave and bu..
IE can only handle 2 at a time.  .
The 2nd bu list will display according to the selected wave.  There
are 2 bu lists.  One is hidden.  I have it visible right now for
testing.
The selectObj forms the  bu list for the selected wave.
The RegEx object searches through the hidden list comprising both bu
and wave to find the right bu's for the wave selected and displays in
the select object..
The bu's are 5 digits that is why the substring is 5, as I mentioned
the first number is the wave and the rest is the bu in the hidden
option list.
I just have to find out where this error message is coming from.
thanks,

function fillBu(){
    var functionlist=new Array();
    var wv=document.forms[0].search_wave.value;
    var selectObj=document.forms[0].search_bu;
    var maxNumToShow=20;

    for (i=0;i< document.forms[0].hiddenWVBU.options.length;i++){
        functionlist[i]=document.forms[0].hiddenWVBU.options[i].text;

    }
    functionListLength=functionlist.length;
        searchPattern="^"+wv;
        re=new RegExp(searchPattern,"gi");
        //Clear the options list
        selectObj.length=0;
        numShown=1;
    selectObj[0]=new Option("Select BU","");
        for(i=0;i< functionListLength;i++) {
            if(functionlist[i].search(re) != -1){
                selectObj[numShown]= new
Option(functionlist[i].substring(5)),functionlist[i].substring(5));
******
                numShown++;
        }
        if(numShown==maxNumToShow){break;}
    }
    if(selectObj.length==1){selectObj.options[0].selected=true;}
}


Here is the drop down section of the search form.
<form name='mySearchForm' id ='mySearchForm' action='/tools/
cart_inventory/print_labels_formo.php'  method='post'>
PAGE: <table align='center' style='border:1px solid ;'>
<th align='right'><span class='ast'>*</span>Wave
<td><select name='search_wave' id='search_wave' onChange='fillBu();'
style='font-family;verdana;'>
<option value=''>Select Wave</option>
<option value='0' >0</option>
<option value='1' >1</option>
<option value='2' >2</option>

<option value='3' >3</option>
<option value='4' >4</option>
<option value='5' >5</option>
<option value='6' >6</option>
<option value='7'>7</option>
<option value='8' >8</option>
<option value='9' >9</option>
</select>
<tr>
<th align='right'><span class='ast'>*</span>BU | BU Descr

<td><select name='search_bu' id='search_bu' onChange='fillZoneNm();'
style='font-family:verdana;'>
<option value=''>Select BU</option>
<option value='08103' >08155 </option>
...........................
<option value='08136' >08178 </option>

</select>
<option value=''>Select BU</option>
<option value='008132'>008992</option>
................................

<option value='308245'>309992</option>
</select>
<tr>
<th align='right'>Zone Number</th>
<td><div id='searchzonenm'>
<select name='search_zonenm' id='search_zonenm'
onChange='fillZoneId();' >
<option value=''>Select Zone Number</option>
<option value='' SELECTED></option>
<option value='' SELECTED></option>
<option value='adds' >adds</option>
................
<option value='Yellow Safe' >Yellow Safe</option>

</select>
</div>
</td>
</tr>
<tr>
<th align='right'>Zone Id</th>
<td><div id='searchzoneid'>
<select name='search_zoneid' id='search_zoneid'>
<option value=''>Select Zone Id</option>
<option value='' SELECTED></option>
<option value='0201' >0201</option>
<option value='0202' >0202</option>
   ..................
<option value='605' >605</option>
</select>
</div>
-1
Reply jlrough (485) 1/6/2011 8:35:47 PM

Am 2011-01-06 21:35, jr meinte:
> I am getting the syntax error message "missing ; before statement" on
> the line with the asterisks.

And? It's not *that* hard to spot.

[prose snipped]

> selectObj[numShown]= new
> Option(functionlist[i].substring(5)),functionlist[i].substring(5));
        ^                         ^ ^^                          ^ ^^
3 open... 4 close...

Gregor


-- 
http://vxweb.net
0
Reply Gregor 1/6/2011 8:47:26 PM


jr wrote:

> I am getting the syntax error message "missing ; before statement" on
> the line with the asterisks.
[...]
>                selectObj[numShown]= new
> Option(functionlist[i].substring(5)),functionlist[i].substring(5));
> ******

It seems that you have an extraneous closing parentheses ")" there:
Option(functionlist[i].substring(5))
would close the argument list, making the rest of the line homeless. 
Removing the second ")" there should help.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/ 

0
Reply Jukka 1/6/2011 8:48:02 PM

On Jan 6, 12:47=A0pm, Gregor Kofler <use...@gregorkofler.com> wrote:
> Am 2011-01-06 21:35, jr meinte:
>
> > I am getting the syntax error message "missing ; before statement" on
> > the line with the asterisks.
>
> And? It's not *that* hard to spot.
>
> [prose snipped]
>
> > selectObj[numShown]=3D new
> > Option(functionlist[i].substring(5)),functionlist[i].substring(5));
>
> =A0 =A0 =A0 =A0 ^ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ^ ^^ =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0^ ^^
> 3 open... 4 close...
>
> Gregor
>
> --http://vxweb.net

thanks ,
0
Reply jr 1/6/2011 9:02:27 PM

On Jan 6, 12:48=A0pm, "Jukka K. Korpela" <jkorp...@cs.tut.fi> wrote:
> jr wrote:
> > I am getting the syntax error message "missing ; before statement" on
> > the line with the asterisks.
> [...]
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0selectObj[numShown]=3D new
> > Option(functionlist[i].substring(5)),functionlist[i].substring(5));
> > ******
>
> It seems that you have an extraneous closing parentheses ")" there:
> Option(functionlist[i].substring(5))
> would close the argument list, making the rest of the line homeless.
> Removing the second ")" there should help.
>
> --
> Yucca,http://www.cs.tut.fi/~jkorpela/

thanks both,
0
Reply jr 1/6/2011 9:02:38 PM

Jukka K. Korpela wrote:

> jr wrote:
>> I am getting the syntax error message "missing ; before statement" on
>> the line with the asterisks.
> [...]
>>                selectObj[numShown]= new
>> Option(functionlist[i].substring(5)),functionlist[i].substring(5));
>> ******
> 
> It seems that you have an extraneous closing parentheses ")" there:
> Option(functionlist[i].substring(5))
> would close the argument list, making the rest of the line homeless.
> Removing the second ")" there should help.

ACK.  Also, the values of the arguments to Option() would be identical, and 
they are produced by a property lookup (perhaps a collection item lookup) 
and a method call operating on a string value, both of which can be quite 
expensive.  So it would be a good idea to store that value in a variable and 
use that variable instead.  That would also make the code better readable.

  var optionValue = functionlist[i].substring(5);
  selectObj[numShown] = new Option(optionValue, optionValue);

And it SHOULD (MUST?) be

  selectObj.options[numShown] = new Option(optionValue, optionValue);

here because of

  var selectObj = document.forms[0].search_bu;

before which should be

  var selectObj = document.forms[0].elements["search_bu"];

or even

  var es = thisObj.form.elements;
  // …
  var selectObj = es["search_bu"];

as

  function fillBu(thisObj)
  {
    // …
  }

could be passed `this' in the event-handler attribute, and both controls are 
part of the same form.


PointedEars
-- 
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
  -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>
0
Reply Thomas 1/6/2011 9:02:48 PM

On 06/01/11 20:35, jr wrote:
> I am getting the syntax error message "missing ; before statement" on
> the line with the asterisks.

This is probably because you have a syntax error in that line.

Hint: Count the open and close brackets in the line.

selectObj[numShown]= new
   Option(functionlist[i].substring(5)),functionlist[i].substring(5));
This..................................^
Closes...^

So the statement:

selectObj[numShown]= new
   Option(functionlist[i].substring(5))

should be followed by ";"

and then the next statement is:

,functionlist[i].substring(5));

which will cause another syntax error, because there's a leading comma
and an unopened bracket.

And if I correct it syntactically to:

functionlist[i].substring(5);

It is not a syntax error, but I suspect it will have no effect, as you
are not using the result.

Perhaps instead you meant to do this:

selectObj[numShown]= new
   Option(functionlist[i].substring(5),functionlist[i].substring(5));

Although I'm not quite sure why you're passing the same string to both,
and if you're trying to create new option elements in an existing select
list, wouldn't you be better off using something like:

/*
 * selId is id of the select to add the option to
 * optTxt is text to display for the option
 * optVal is value to return in select when option selected
 * optId is id to assign to option (may be null)
 * beforeId is Id before which to insert option (may be null)
 */

function addOptToSel(selId, optTxt, optVal, optId, beforeId) {
  var o = document.createElement('option');
  o.text = optTxt;
  o.value = optVlue;
  o.id = optId;
  var s = document.getElementById(selId);
  var b = document.getElementById(beforeId);
  try {
    s.add(o, b); /* real browsers */
    }
  catch(e) {
    s.add(o); /* braindead shit */
    }
  }

which inserts a new option element before a specified option id or at
the end of the list.

If you just want to add options to the select object and are not
bothered about list order, call it as:

addOptToSel(selectId, text, value, "", "");

Rgds

Denis McMahon
0
Reply Denis 1/6/2011 11:23:45 PM

6 Replies
1566 Views

(page loaded in 0.181 seconds)

Similiar Articles:













7/21/2012 5:34:29 PM


Reply: