selectizeInput ID is null

Hi,

I'm trying to use javascript to refer to an selectizeinput but the ID comes back null even if I see it in the page source for .

I try to use :
document.activeElement.getAttribute("id")
I look at the page source HTML and see:

<select id="myid" class="form-control" multiple="multiple">

I got the outerhtml

<input type="text" autocomplete="off" tabindex="" style="width: 25.2344px; opacity: 1; position: relative; left: 0px;" placeholder="ALL">

I see no ID, any thoughts how I could use javascript to get the ID of the <select>?

Here's a small shiny app that I ran and inspected in Chrome:

library(shiny)
library(tidyverse)

ui <- fluidPage(
  
  selectizeInput(
    inputId = "filter_carb",
    label = "Filter 1: carb",
    selected = 1,
    choices = unique(mtcars$carb)
  )
)

server <- function(input, output) {
}

shinyApp(ui = ui, server = server)

I'm able to access the value and/or text of the selectizeInput by the following jQuery statements:

$("#filter_carb :selected").text()
$("#filter_carb :selected").val()

Does that work for you?


Reference: https://stackoverflow.com/questions/1085801/get-selected-value-in-dropdown-list-using-javascript

1 Like