I called a function within script tag from an input value, but it throws Error — call to undefined function
Here is the function definition
<script>
function getSelectValue(sel){
var lang=sel.options[sel.selectedIndex];
return lang;
}
</script>
I called the function here
<div class="form-group">
<input type="hidden" id="value" value="{{getSelectValue(this)}}" >
<label for="audiolang" class="input-label">Audio Language</label>
<select id="audio_lang" name="audio_lang" class="form-control " onchange="getSelectValue(this)">
<option selected disabled value="">Select Language</option>
<option value="1">English</option>
<option value="2">Arabic</option>
<option value="3">Urdu</option>
<option value="4">Hindi</option>
</select>
</div>
Why this error **call to undefined function getSelectValue() ** is coming.
>Solution :
As I understood you have select in your code and you want to get the selected value.
In select
<select id="mySelect" onchange="setHiddenFieldValue(this)">
In input
<input type="hidden" id="hiddenField">
In function
function setHiddenFieldValue(sel) {
var lang = sel.options[sel.selectedIndex].value;
console.log(lang);
document.getElementById("hiddenField").value = lang; // to set the value
}