How to get the value from jQuery UI selectable in php [closed]

蓝咒 提交于 2019-12-13 22:17:18

问题


Hello I have created this list which changes the colour when you select an item using jQuery UI's selectable.

 <ol id="selectable">
      <li class="ui-widget-content" Name ='gender' value= 'male1'>Item 1</li>
      <li class="ui-widget-content" Name ='gender' value= 'male2'>Item 2</li>
      <li class="ui-widget-content" Name ='gender' value= 'male3'>Item 3</li>
      <li class="ui-widget-content" Name ='gender' value= 'male4'>Item 4</li>
      <li class="ui-widget-content" Name ='gender' value= 'male5'>Item 5</li>
      <li class="ui-widget-content" Name ='gender' value= 'male6'>Item 6</li>
      <li class="ui-widget-content" Name ='gender' value= 'male7'>Item 7</li>
    </ol>

<Input type = "Submit" Name = "Submit1" VALUE = "Select a Radio Button">

http://jsfiddle.net/szNh3/2/

Ho do I send/get the selected item in a php file?


回答1:


Slightly modified segment from the jQuery UI documentation

$(function() {
    $( "#selectable" ).selectable({
        stop: function() {
            var result = $( "#select-result" ).empty();
            $( ".ui-selected", this ).each(function() {
                var index = $( "#selectable li" ).index( this );
                // send an AJAX request to a PHP file
                $.get('myphpfile.php', {
                    selectedIndex: index
                }, function(data) {
                    // do stuff with the results from PHP
                });

            });
        }
    });
});

EDIT

To do this from your button

$(function() {
    $( "#selectable" ).selectable();

    $("submit[name=Submit1]").click(function() {
        var index = $( "#selectable li" ).index( $("#selectable") );
        $.get('myphpfile.php', {
            selectedIndex: index
        }, function(data) {
            // do stuff with the results from PHP
        });
    });
});


来源:https://stackoverflow.com/questions/24618319/how-to-get-the-value-from-jquery-ui-selectable-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!