-->

How use Select Option in Watson Conversation

2019-08-03 03:19发布

问题:

I'm trying to insert the select options tag into my conversation, to make it more simple to the user. I did this:

And in the index.js:

function selected(){
switch($('#selected option:selected').val()){
    case 01:
       alert("01");
        break;
    case 02:
        alert("02");
        break;
}
};

But it doesn't recognize the option selected. I tried without the function selected() (only with switch case), but it didn't worked.. Can somebody help me please? Thanks a lot!

回答1:

I believe your HTML inside the Advanced context have something you miss.

In your HTML in onselect your typed :, but, for use onselect and call one function you have to use onselect="nameFnction()"

See one simple example inside MDN to use this tag:

<input type="text" onselect="myFunction()" value="Hello world!">

Now, see other example for works fine according the choice:

<select>
  <option onclick="doSomethingA(this);">A</option>
  <option onclick="doSomethingB(this);">B</option>
  <option onclick="doSomethingC(this);">C</option>
</select>

And with jQuery (Your id is select and not selected):

$('#select option:selected').val()