For my javascript code I tried the 2 alternative solutions in Get the value in an input text box, answer 2 from RJD22, pls see code below. Option A works fine, but option B doesnt; the console shows 'undefined' when I enter a figure (or even some text).
Any idea why B does not work? I could use option A but I want to validate that the form field has been filled in, and from the val() description (http://api.jquery.com/val/) I cannot see what val() returns when no value has been filled in.
Thnx for any comments in advance.
html code:
</label> <input id="usage" type="text" name="usage">
javascript code:
this.usage = $("#usage").val(); //OPTION A: WORKS
this.usage = $("#usage").attr("value"); //OPTION B: DOESNT WORK
console.log(this.usage);