I need to get the value of the username field when the browser prepopulates it. The javascript is on a cshtml page. I have tried getting it in the document.render function, but the value is empty. I tried this using the below code in the render function.
console.log(document.getElementById("Username").value.length);
if (document.getElementById("Username").value.length > 0)
setTimeout(function () { CallCheckUsernameAvail($("#Username")); }, 1);
I also tried to create a document.load function, but even empty, it throws an error in the jquery files (image below)
$(document).load(function () { });
Image of jQuery url indexOf error from dev tools
Can someone advise how I might access this value when the page first loads? Thanks!
assuming that the ID: Username
belongs to the input field your trying to retrieve the info from you should be able to do something like this
$("#Username").val();
if its being populated automatically you might need to use a delay or some other crafty method to ensure that the info your trying to get is in the field before your jQuery looks for it, possibly something like this.
$("#Username").delay( 800 ).val();
Both of these are JQuery solutions
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.