jQuery UI Widgets Forums Lists DropDownList How to original index of array

This topic contains 3 replies, has 2 voices, and was last updated by  Neelam 12 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • How to original index of array #4843

    Neelam
    Member

    Hello,

    I have php array which am using javascript. I want to get original index of selected item on onchange event. But while builing the dropdown indexes get reordered like 0,1,2 and onwards. below is my code.

    var sourceA = new Array();
    groups as $k=> $v)
    {
    echo ‘sourceA[‘.$k.’] = “‘. $v .'”;’;
    }
    ?>
    $(“#jqDropDownA”).jqxDropDownList({ source: sourceA, selectedIndex: 0, width: ‘150’, height: ’25’ });

    Thanks in advance.

    How to original index of array #4846

    Peter Stoev
    Keymaster

    Hi Neelam,

    You can save your “original” index as a value of the items. Each list item has ‘label’ and ‘value’. The ‘label’ is what is going to be displayed, the ‘value’ could be your index.

    For example, for value in the code below, set the “original” index:

    var source = [{
    label: "Hot Chocolate",
    value: "Chocolate Beverage"
    }, {
    label: "Peppermint Hot Chocolate",
    value: "Chocolate Beverage"
    }, {
    label: "Salted Caramel Hot Chocolate",
    value: "Chocolate Beverage"
    }, {
    label: "White Hot Chocolate",
    value: "Chocolate Beverage"
    }, {
    label: "Caffe Americano",
    value: "Espresso Beverage"
    }, {
    label: "Caffe Latte",
    value: "Espresso Beverage"
    }, {
    label: "Caffe Mocha",
    value: "Espresso Beverage"
    }, {
    label: "Cappuccino",
    value: "Espresso Beverage"
    }, {
    label: "Caramel Brulee Latte",
    value: "Espresso Beverage"
    }, {
    label: "Caramel Macchiato",
    value: "Espresso Beverage"
    }, {
    label: "Peppermint Hot Chocolate",
    value: "Espresso Beverage"
    }, {
    label: "Cinnamon Dolce Latte",
    value: "Espresso Beverage"
    }, {
    label: "Eggnog Latte",
    value: "Espresso Beverage",
    }, {
    label: "Espresso",
    value: "Espresso Beverage"
    }, {
    label: "Espresso Con Panna",
    value: "Espresso Beverage"
    }, {
    label: "Espresso Macchiato",
    value: "Espresso Beverage"
    }, {
    label: "Flavored Latte",
    value: "Espresso Beverage"
    }, {
    label: "Gingerbread Latte",
    value: "Espresso Beverage"
    }, {
    label: "White Chocolate Mocha",
    value: "Espresso Beverage"
    }, {
    label: "Skinny Peppermint Mocha",
    value: "Espresso Beverage"
    }, {
    label: "Skinny Flavored Latte",
    value: "Espresso Beverage"
    }, {
    label: "Pumpkin Spice Latte",
    value: "Espresso Beverage"
    }, {
    label: "Caffe Vanilla Frappuccino",
    value: "Frappuccino Blended Beverage"
    }, {
    label: "Caffe Vanilla Frappuccino Light",
    value: "Frappuccino Blended Beverage"
    }, {
    label: "Caramel Brulee Frappuccino",
    value: "Frappuccino Blended Beverage"
    }, {
    label: "Caramel Brulee Frappuccino Light",
    value: "Frappuccino Blended Beverage"
    }, {
    label: "Eggnog Frappuccino",
    value: "Frappuccino Blended Beverage"
    }, {
    label: "Mocha Frappuccino",
    value: "Frappuccino Blended Beverage"
    }, {
    label: "Tazo Green Tea Creme Frappuccino",
    value: "Frappuccino Blended Beverage"
    }]
    // Create a jqxListBox
    $("#jqxWidget").jqxListBox({ source: source, width: 200, height: 250, theme: theme });

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    How to original index of array #4848

    Neelam
    Member

    Thanks, worked fine after a lot trail.

    How to original index of array #4893

    Neelam
    Member

    Hi,

    As you know, I have to access the value of selected item so its necessary to build the array in your given format. But when my ajax request goes, I am building the array in label, value format to access the value but json dont process it the way it should do.

    Shall I need to use json_encode() in php action.

    Thanks in advance.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.