In Laravel, I have a function defined on the blade to capture the selected text in a drop-down list:
<script type="text/javascript">
function sacar_nombre(){
var combo = document.getElementById('titulo');
var titulo = combo.options[combo.selectedIndex].text;
}
</script>
Now I want to use the variable "title" in an external Javascript file linked to the blade.
<script src="{{ asset('/js/grafico.js') }}"></script>
But when trying to show it from the external file, I get the following: "[object HTMLSelectElement]"
The code of the external file is as follows:
const CHART = document.getElementById("lineChart");
console.log(CHART);
let lineChart = new Chart(CHART, {
type: 'line',
data: {
labels: ["10/7/2017", "11/7/2017", "12/7/2017", "13/7/2017",
"14/7/2017", "15/7/2017"],
datasets: [
{
label: titulo,
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(75,192,192,0.4)",
borderColor: "rgba(75,192,192,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(220,220,220,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data: [10,6,9,8,8,7],
}
]
} });
The variable I use in the label "label".
Could someone help me?
Thank you very much.