How do you access a droplist value from JavaScript?

Very simple: I have a dropdown list.
onChange: want to send the selected value somewhere.

HOW?

Here’s my current code. I’ve tried many different combinations of VAIL. Does someone have working code?

var dL = client.getWidget(“Droplist1”);

var result = dL.options[dL.selectedIndex].value;
var http = new Http();
http.setVantiqUrlForSystemResource(“topics”);
http.setVantiqHeaders();

http.publish(result,”/POCBoo/eventStream”,function(response)
{ …

 

Posted: June 18, 2020 at 5:39 pm
Replies: 1
Jun 18, 2020
Posted by Ken

The documentation for the droplist is here:
https://dev.vantiq.com/docs/system/cbref/index.html#droplist

There are two common solutions to this question. The first solution uses the “boundValue” property of the droplist. Your complete onChange event code might look like this:

var http = new Http();
http.setVantiqUrlForSystemResource("topics");
http.setVantiqHeaders();

var dL = client.getWidget("Droplist1");
var theMessageObject = dL.boundValue;

var topicName = "/POCBoo/eventStream";

http.publish(theMessageObject,topicName,function(response)
{
    // "response" is meaningless for a "publish"
},
function(errors)
{
    client.showHttpErrors(errors,"Doing a publish on a topic");
});

The second solution makes use of the “Data Binding” property of the droplist. If you set the DataBinding value for the droplist to a variable in the page.data properties, it will automatically be updated. You can do the following:

– Create a data object. For example: page.data.dlDataValue (integer)
– Set the “Data >> DataBinding” property of the droplist to the data object
– Replace the two “dL” lines of code in the example above with the following:

var theMessageObject = page.data.dlDataValue;

  • This reply was modified 4 years, 5 months ago by Ken.
  • This reply was modified 4 years, 5 months ago by Ken.
  • This reply was modified 4 years, 5 months ago by Ken.
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
© Vantiq 2024 All rights reserved  •  Vantiq Corporation’s Privacy Policy and Cookie Policy