1

I have a simple javascript/jquery function:

jQuery(document).ajaxSuccess(function(e, xhr, settings) {
   var widget_id_base = '099_cf_samurai_widget';

   if(settings.data.search('action=save-widget') != -1 &&
        settings.data.search('id_base=' + widget_id_base) != -1) {
         my_function_chosen_o99();
   }
}); 

function my_function_chosen_o99(){
   jQuery(".chzn-select").chosen();
}

Which works correctly, but when I add the width parameter:

function my_function_chosen_o99(){
   jQuery(".chzn-select").chosen(width:'95%');
}

It gives me an error:

Error: SyntaxError: missing ) after argument list
Source File: http://localhost/my-path/js/o99.chosen.init.js?ver=k99
Line: 20, Column: 41
Source Code:
      jQuery(".chzn-select").chosen(width:"95%"); 
.............................................|

What is wrong with this code?

1
  • It is related to a javascript syntax error Commented Nov 13, 2013 at 15:51

1 Answer 1

9

You need to pass an object as the argument(within {})

 jQuery(".chzn-select").chosen({width:'95%'});
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you dear sir ... But why ?? I just followed the official documentation found here : harvesthq.github.io/chosen/options.html . is the documentation wrong ? I mean the problem is resolved , but I would really want to learn the reason :-)
@ObmerkKronen looks like there is a typo in that documentation
oh .. ok . Thanks. so for future reference - I ALWAYS need to pass options in that manner {} ??
@ObmerkKronen it depends on the function... but if it is an settings object then yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.