Select menu value undefined when called on in another function

Viewed 29

I have a vanilla javascript file as i am trying to develop my vanilla js knowledge, I have this problem where I am calling another function when a button is clicked and this function should be passed the value from my select menu.

But if i load up my page and then click the button without touching the select menu it says the select menu value is undefined, even though i set a defaul selected option

does anyone know why this is?

here is my code snippets:

        <select name="cur" id="cur" onclick=getRate(document.getElementById('cur').value)>
            <option value="x">x</option>
            <option value="y" selected="selected">y</option>
            <option value="z">z</option>

function finalVal() {
  let symbolHome = getRate(document.getElementById('cur').value)[1];

I have checked getRate function and it returns values properly in an array of size 4 [x,y,z,a]

0 Answers
Related