I have a textbox in which I can provide a string. When I ran the debugger (both IE and Chrome), I can see that the string it reads does not contain my input, but instead "" (an empty string). -Actually there are two textboxes, but they are similar.
The box and my code looks like this, Html part:
<table>
<tbody><tr><td>Type value here</td><td>Type second value here</td></tr>
<tr><td><input id="MTY1" type="text"></td><td><input id="MTY2" type="text"></td></tr>
<tr><td></td><td><button name="btnGetPerson" onclick="GetPerson();">Retrieve info</button></td></tr>
Jquery part:
MyTypedValue1 = $('#MTY1').val();
MyTypedValue2 = $('#MTY2').val();
I found many closely related answers to this question. And I have tried the following:
MyTypedValue1 = $('#MTY1').value();
MyTypedValue2 = $('#MTY2').value();
MyTypedValue1 = $('#MTY1');
MyTypedValue2 = $('#MTY2');
I have also tried the Js form:
var MyTypedValue1 = document.getElementById("MTY1").value;
var MyTypedValue2 = document.getElementById("MTY2").value;
w3school has a great working example. But still I get the empty string. https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_dom_val_get.
I have tried all of the above with and without the type 'var' and the element in single and double '' "". Also I have been instructed to make this in Jquery and not JavaScript. But atm. I will accept anything that works.
Can anyone tell what I am doing wrong?
Thanks.
Edit: To recap, since the error was another place in the code, the Jquery code bit being used is correct:
MyTypedValue1 = $('#MTY1').val();
MyTypedValue2 = $('#MTY2').val();

.value();?or.val()?