Ressources » JavaScript

Documentation jSelect

Documentation about jQuery jSelect, plugin that enables to manage and load data in Select element.

Specifications

  1. HTML
    ‹option value="0" selected="selected" class="my-class"›Option One‹/option›
  2. XML
    ‹select›
        ‹option value="0" text="Option One" selected="true" class="my-class" /›
    ‹/select›
  3. Array:
    [ [ "value", "text", "selected:bool", "class" ] ] ou
    [ "one", "two" ] ou
    [ "one", [ "value", "text", "selected:bool", "class" ] ]
  4. JSON:
    { "select" : [ { "oValue": "0", "oText": "Option One", "oSelected": "true", "oClass": "my-class" } ] }

Example

$('#load_select').jselect({
     data: [ [ 0, "Option First" ], [ 1, "Option Second", true, "my-class" ] ],
     onChange: function(value, text){ isChange(value, text); },
     loadUrl: "jselect.xml",
     addOption: true,
     addOptionUrl: "new-option.php"
});

Configuring jSelect

data[]Array that contains all elements to create the new Option (and Options by default)
dataType"array"Defined default data type (xml, array, json and html)
replaceAlltrueReplace content before adding new data?
onChangefunction(){}Function called on change of Select (return: value and text of selected Option and current jSelect element)
onCompletefunction(){}Function called when the process is done
loadUrlnullURL called to load XML, HTML or JSON data
loadDatanullParameters to complete URL to load
loadType"POST"Defined loading type (POST or GET)
loadOnErrorfunction(){}Function called if an error occured when loading data
loadDataType"xml"Defined loading data type (xml, array, json and html)
addOptionfalseSet action to add option by prompt
addOptionUrlnullURL called to save Option added in Select. Get ID of this new Option in return.
addOptionData"newOption="Parameter name containing the text of the new option sent to addOptionUrl.
addOptionType"POST"Defined sending type (POST or GET)
addOptionValue"-1"Value of Option "Add an option"
addOptionText"Add an option"Text of Option "Add an option"
addOptionClassnullClass of Option "Add an option"
addOptionPrompt"Text of the new option:"Text of the prompt to add an Option
addOptionSetSelectedtrueThe new Option must be selected after added ?
addOptionSetClassnullClass of the new Option added
addOptionOnCompletefunction(){}Function called when process to add of Option is done (Only in version >= 1.1)
addOptionOnErrorfunction(){}Function called if Option wanted has ""(empty) as value (return: text wanted for Option and current jSelect element)