ozkank
ozkank

Reputation: 1462

Set textbox value

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

Answers (3)

Pranay Rana
Pranay Rana

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:

  • If you are making use of id then there is no need to write input#....
  • This is a jQuery function. It's not pure JavaScript.

Upvotes: 4

Camilo Martin
Camilo Martin

Reputation: 37898

I think it gives you an error because you're trying to assign a value to a function.

Upvotes: 0

John
John

Reputation: 164

You should be able to just use $("#textboxId").val("some text"); What error does it give when you try this?

Upvotes: 0

Related Questions