Question

Internet Explorer 8 and 7 fails with error when i update the select box with new option and choose the selected option. In other browsers this works fine and without errors. I use Mootools 1.2.3.

<?php
    $getdestiny=$_GET['dest'];
    $getcountry=$_GET['countr'];

    print "<script type='text/javascript'>
        window.addEvent('domready', function() {

       var countrh=$getcountry;
       var desth=$getdestiny;

       if (countrh==4){
             $('destination').options.length=0; //error fails here   
             var opt0 = $('destination').options[0] = new Option('Сhoose Destination',0);
             var opt1 = $('destination').options[1] = new Option('London-Aberdeen','1');

              var len = $('destination').options.length;
              if (desth < len){
             opt$getdestiny.setProperty('selected','selected'); //or here

        else {
        //do nothing
        }
    });
    </script>"

Can it be because i use double-assignment for vars opt* or what can it be else? Advise me please.

Was it helpful?

Solution

It looks like you just have a syntax error here where you're getting your 2nd error at.

if (desth < len){
   opt$getdestiny.setProperty('selected','selected'); //or here
else {
  //do nothing
}

is missing a closing } for the first part of the if statement. Should be like this:

if (desth &lt; len){
   opt$getdestiny.setProperty('selected','selected'); //or here
}else {
  //do nothing
}

ADDENDUM:

Ok your problem is that you're trying to use a MooTools function on an element that's not wrapped in MooTools. You can fix this by wrapping it in a $() function like this:

$(opt$getdestiny).set('selected','selected');

I also typically just set selected = true so you can try that as well. Make sure to use true, not the string 'true'.

OTHER TIPS

In the past we have used the following syntax successfully to mark a select option element as "selected":

option.selected = true;

in mootools 1.2, setProperty() got deprecated. the prototype is now just element.set(prop, value); - one setter and one getter (element.get()) for anything :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top