jQuery UI Widgets › Forums › Lists › DropDownList › specified values?
This topic contains 2 replies, has 3 voices, and was last updated by bitman0101 12 years, 3 months ago.
-
Authorspecified values? Posts
-
I very much like the way the dropdown looks and can be formatted, and I’d like to use your tools for a complete page. I don’t see how to tie the dropdown list to data selections though.
Ordinarily, I would create the drop down in html (via php) like this:
<option value="0" selected>Please Select One</option>
<option value="10" >A Option</option>
<option value="231" >B Option</option>
<option value="42" >C Option</option>
<option value="3" >D Option</option>Where the values reflect record IDs in a database. Can I do that here? It would be great to be able to feed the widget an array of value/display pairs, and then select the default option.
Hi Rob,
You can feed the DropDown with value/display pairs very easily. I suggest you to take a look at this article which shows how to bind the jqxDropDownList to MySQL Database using PHP. The jqxDropDownList displays the data from the CompanyName column, but each item is also associated to the ContactName column. This is achieved by using the jqxDropDownList’s displayMember and valueMember properties.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comI originally came here with the same question. I was able to populate my entries with labels and values using the link Peter Stoev posted above.
As I am already doing standard jquery AJAX calls, I prefer to not have to include unnecessary libraries and would prefer to build the data structures myself.
For anyone interested, this is how to build the format without an AJAX call via dataAdapter:
$(document).ready(function () { // prepare the data myRows = [{RecordName: "test1", RecordID: 100}, {RecordName: "test2", RecordID: 200}]; $("#dropdownlist").jqxDropDownList( { source: myRows, theme: 'classic', width: 200, height: 25, selectedIndex: 0, displayMember: 'RecordName', valueMember: 'RecordID' }); var item = $("#dropdownlist").jqxDropDownList('getItem', 1 ); var itemLabel = item["label"]; var itemValue = item["value"]; });
-
AuthorPosts
You must be logged in to reply to this topic.