Tengo un menú desplegable y un enlace. Estoy tratando de pasar el valor desplegable seleccionado a onclick.
<div> <select class="browser-default custom-select" id="venflows"> <option value="marcus">marcus</option> <option value="bruno">bruno</option> <option value="jadon">jadon</option> {% endfor %} </select> </div> <div> <a onclick="window.location.href = 'download/dropdown_selected_value_here'"></a> </div>Aquí estoy tratando de pasar el valor desplegable seleccionado para hacer clic. Ej: si se selecciona marcus al hacer clic, debería ser así
<div> <a onclick="window.location.href = 'download/marcus'"></a> </div>Ej: si se selecciona bruno al hacer clic, debería ser así
<div> <a onclick="window.location.href = 'download/bruno '"></a> </div>Para responder a su pregunta como se planteó
<a onclick="window.location.href = 'download/'+document.getElementById('venflows').value"></a>Pero recomiendo un eventListener
document.getElementById("link").addEventListener("click", function() { const url = `download/${document.getElementById("venflows").value}` console.log(url); // for testing this.href = url; }) <div> <select class="browser-default custom-select" id="venflows"> <option value="marcus">marcus</option> <option value="bruno">bruno</option> <option value="jadon">jadon</option> </select> </div> <div> <a href="" id="link">GO</a> </div>Si quieres un evento onclick, puedes probar esto
<select class="browser-default custom-select" id="venflows" onclick="customFunction(this)"> <option value="marcus">marcus</option> <option value="bruno">bruno</option> <option value="jadon">jadon</option> {% endfor %} </select> <div> <a onclick="window.location.href = 'download/dropdown_selected_value_here'" id="url_nav"></a> </div> function customFunction(curObj){ document.getElementById("url_nav").onclick = "window.location.href = 'download/'+curObj.value+" }