Home › Forums › Programming › Retrieve data from Multiselect list
- This topic has 11 replies, 2 voices, and was last updated 4 years, 9 months ago by Yuri Kovelenov.
-
AuthorPosts
-
2020-01-23 at 3:58 pm #23029David DuperronCustomer
Hi!
I am working on a project where I would like to allow the user to select which “layers” of data to display in the 3D scene, using HTML interface.
I found several multiselct select boxes example on the net, using javascript, but now I don’t know how to access the selected values from my Puzzles…?
Here is an example of the multiselect box: https://www.cssscript.com/demo/single-multi-select-vanilla/
Anyone could help me with that??
Thanks in advance!David
2020-01-24 at 6:29 am #23032Yuri KovelenovStaffHi David,
From the source code of that selector example, I can see that the button
“get select value” executes the following JavaScript code:document.getElementById('brandsOne').value
where brandsOne is the ID of the selector placed on the page:
<select id="brandsOne"></select>
So in Puzzles, this corresponds to get attribute > value puzzle:
https://www.soft8soft.com/docs/manual/en/puzzles/HTML.html#get_attribute
2020-01-24 at 8:14 am #23037David DuperronCustomerHi!
Thanks for your prompt answer! I start to get used to these amazing puzzles, but there is lots to learn!!
And I’m still struggling…
In fact I would like to know if a given option inside:
`<select id=’testSelect1′ multiple>
<option value=’1′>Item 1</option>
<option value=’2′ selected=’selected’>Item 2</option>
<option value=’3′>Item 3</option>
<option value=’4′>Item 4</option>
<option value=’5′ selected=’selected’>Item 5</option>
</select>’is selected or not… I cannot build the proper query for that… :(
2020-01-24 at 8:26 am #23038Yuri KovelenovStaff2020-01-24 at 8:47 am #23041David DuperronCustomerThat would be great Thank you very much!
This dropdown multiselct box is great too I think… this is the one I tried, but I cannot retrieve the “selected” items… :(2020-01-24 at 12:52 pm #23044Yuri KovelenovStaffGot it working
here is what did the trick1. create a parent HTML document to embed the 3D app. (I copied the listing from here)
2. download the multi-select and copy 2 files from there to 3D app folder:
vanillaSelectBox.css
vanillaSelectBox.js3. Remove those 2 buttons from index.html and link 2 vanillaSelectBox files in the header. Also add a selector element with some options and a button to retrieve its values.
4. Edit the app JS file (here – my_awesome_app.js) to add the code for initialization of multi-select, and a function for getting multi-select values. Read about it here.
5. Finally, add onclick puzzle for the button and call JS function puzzle to call the above-mentioned retrieval function
Attached an example – it just prints the multi-select’s values to browser console, but you can now use them to hide 3D objects conditionally.
Attachments:
You must be logged in to view attached files.2020-01-24 at 1:17 pm #23047David DuperronCustomerThat’s awesome!!
Thank you so much! See you at the next stopper!2020-01-24 at 1:59 pm #23048Yuri KovelenovStaff2020-01-24 at 2:46 pm #23049David DuperronCustomerYeah! But thank you anyway!
I’ve managed to set up some select boxes exactly the way I wanted, and I also managed to trigger the display of some elements in the 3D view.
Now one problem appear: for some reason the dropdown list stays open, whatever the option “stayOpen” is set to in the js initialization of the select box… you solve one thing and another appears!! I need to investigate a bit more I guess! Perhaps something to do with CSS…?
Attached the project as it is now! :)2020-01-25 at 9:49 am #23058Yuri KovelenovStaffHi David,
It looks like a click on some other element is required to close a multi-select. I modified your project to explicitly display the UI container element, and also made one of the selectors always open to show the difference.
Nice project BTW!
Attachments:
You must be logged in to view attached files.2020-01-25 at 2:51 pm #23061David DuperronCustomerYou’re too good! (and you should take a break during your week-ends! ;))
I was suspecting something with the styling, and that was it… transparent background was not OK! :)2020-01-26 at 9:13 am #23065Yuri KovelenovStaff -
AuthorPosts
- You must be logged in to reply to this topic.