0

I have been given this code by the ui designer and I dont know how to post the selected source array data to a php script so I can query it with MySQL, I am sorry I a beginner with JQuery, I would like to query the array like in a form option select style, or would it be better to use an associative array?

<div id='content'>
  <script type="text/javascript">
    $(document).ready(function () {
        var source = [
            "Select Your location",
            "North London",
            "South London",
            "West London",
            "East London",
            "City of London",  
        ];

        // Create a jqxDropDownList  
        $("#jqxDropDownList").jqxDropDownList({ 
            source: source,    
            selectedIndex: 0, 
            width:   '250px', 
            height: '35px', 
            theme: 'summer' 
        });
    });
</script>
<div id='jqxDropDownList'>
j0k
  • 22,600
  • 28
  • 79
  • 90
Jon
  • 1,328
  • 1
  • 11
  • 11

1 Answers1

2

If you need to just use this fancy dropdown as normal dropdown, here is the example (no need for ajax):

<html>
<head>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

    <script type="text/javascript" src="jqwidgets/jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="jqwidgets/jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="jqwidgets/jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="jqwidgets/jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="jqwidgets/jqwidgets/jqxdropdownlist.js"></script>

</head>
<body>
<div id='content'>
  <script type="text/javascript">
    $(document).ready(function () {
        var source = [
            "Select Your location",
            "North London",
            "South London",
            "West London",
            "East London",
            "City of London",  
        ];

        // Create a jqxDropDownList  
        $("#jqxDropDownList").jqxDropDownList({ 
            source: source,    
            selectedIndex: 0, 
            width:   '250px', 
            height: '35px', 
            theme: 'summer' 
        });

        $('#jqxDropDownList').bind('select', function (event) { 
            $('#location').val($("#jqxDropDownList").jqxDropDownList('getSelectedItem').label);        
        });

    });


</script>
<div id='jqxDropDownList'></div>

<form>
<input type="text" id="location" name="location" value="not selected" />
<input type="submit" value="selected!">
</form>

<div><?php if (isset($_GET['location'])) print('You selected: '.$_GET['location']); ?></div>

</div>
</body>
</html>
  1. Download and use jqwidgets library.
  2. Bind a select event to jqwidgets dropdown, which puts selected value to normal (hidden) form element.
  3. Submit and use in PHP as normal submitted value

More information: JQWidgets dropdown homepage

Rauli Rajande
  • 2,010
  • 1
  • 20
  • 24