- This topic has 7 replies, 2 voices, and was last updated 13 years, 4 months ago by kaza007.
-
AuthorPosts
-
kaza007MemberHi,
sorry if this has already been answered but I cant seem to find the answer…I am trying to load a combobox from a list in an xml file.
The list is fruits.xml
<select> <option>Apples</option> <option>Lemons</option> <option>Strawberrys</option> <option>Peaches</option> <option>Grapefruit</option> </select>
and the html code to display the combobox is load_fruit.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <body> <select> <script type="text/javascript"> <!-- var xmlDoc=new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("fruits.xml") nodes=xmlDoc.documentElement.childNodes for (i=0;i<nodes.length;i++) { document.write('<option value="'+(i+1)+'">'+nodes.item(i).text+'</option>'); } // --> </script> </select> </body> </html>
Now,
if I extract the javascript and call it a function like load_fruit, where do I place the call so the mobi page will display correctly and be able to select the options?Thanks.
support-michaelKeymasterPlease see the following article that I posted last week on how to populate a list with dynamic content:
http://www.genuitec.com/support-mobione/viewtopic.php?f=14&t=1858
kaza007MemberThanks Wayne,
that was very helpfull.I modified the code to read the list contents from an xml file. It works well!
http://dl.dropbox.com/u/16764856/custom-list-from-xml.zipMy next task is to try and write something simillar now with a combobox.
Let you know how I ago. Will post the results.
kaza007MemberOK,
I am having problems working out how to add items to a combobox in iterations.
(ie. cycling through each line of an xml file and adding each line to the combobox)The following code works nicely.
function buildList() { var list = $('#m1-list-panel1') //remove current list items list.children('#m1-list-hidden-select-combobox1').remove(); list.append( ' <div class="m1-aux-hidden-div">'+ ' <select id="m1-list-hidden-select-combobox1" name="combobox1">'+ ' <option value="value1" label="Apple" selected>Apple</option>'+ ' <option value="value2" label="Pear">Pear</option>'+ ' <option value="value3" label="Banana">Banana</option>'+ ' <option value="value4" label="Grape">Grape</option>'+ ' </select>'+ ' </div)'); }
I have tried many combinations but I can seem to find how to loop the list.append command and make it work!
support-michaelKeymasterTake a look at this screenshot of a simple UI where the Add Item button will append a new item to the combo box each time it is pressed. The Add Item button calls the addItem() javascript function that I wrote. The src code for this example is attached below.
See attachment addItem-screenshot.pngSource Code
See attachment dynamic-combobox-example.zipAttachments:
You must be logged in to view attached files.
kaza007MemberThanks for the example. Your code was in 1.2.2 but I got what I needed out of the source.
Do you have any documentation yet on all the Attributes of the Components that can be used?
I am particulaly after an option to ‘remove’ all the items in the combobox before I ‘append’ the new ones. ‘remove’ does not seem to work. Maybe I am missing an option or parameter.
support-michaelKeymasterI completely forgot that I was testing the upcoming 1.2.2 release when I generated that example code.
Here are a couple of javascript snippets:
Remove all items from combo:
$('#m1-dyna-combobox-hidden-select-combobox1').empty();
Select an item:
$('#m1-dyna-combobox-hidden-select-combobox1').val('valueIProvidedInComboItemsList');
kaza007MemberThanks Wayne,
they were very usefull.Set width of combobox
$('#m1-dyna-combobox-hidden-select-combobox1').width(150);
I would like to add some javascript to the combo change selection event.
Any ideas how I would do that? -
AuthorPosts