Reputation: 1462
How can I set the value of a textBox value using Javascript?
I can read the value of the txtUserName
field in my AJAX method. But in the two commented rows give an error:
function handle_geolocation_query(position) {
// $("input#MainContent_txtEnlem").val() = position.coords.latitude;
// $("input#MainContent_txtBoylam").val() = position.coords.longitude;
PageMethods.SendLocation($("input#MainContent_txtUserName").val(), position.coords.latitude, position.coords.longitude);
}
I'm using jQuery 1.4.1.
Upvotes: 2
Views: 362
Reputation: 176896
The error in you code is that you are assigning the value to function. What you should do is pass the value as agrument, so your code will be:
$("#MainContent_txtEnlem").val( position.coords.latitude);
$("#MainContent_txtBoylam").val(position.coords.longitude);
Some other points:
id
then there is no need to write input#...
.Upvotes: 4
Reputation: 37898
I think it gives you an error because you're trying to assign a value to a function.
Upvotes: 0
Reputation: 164
You should be able to just use $("#textboxId").val("some text"); What error does it give when you try this?
Upvotes: 0