Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set value of input

Tags:

jquery

Sometimes code says more then words, so the following lines work:

 $("#text11").append($(xml).find("address").find("street"));
 $("#<%= tbWoonplaats.ClientID %>").val('testing?');

but these do not:

var street = $(xml).find("address").find("street");
$("#<%= tbAdres.ClientID %>").val(street);

it displays [object object] in the input now i've tried to replace .val(street); with .val(new string(street)); but that doesn't work either

appending to a span works but setting with .val() to input doesn't...

<span id="text11"></span>

EDIT the output of

var street = $(xml).find("address").find("street");
window.alert(street);

is: [object Object]

like image 221
JP Hellemons Avatar asked Jun 04 '10 12:06

JP Hellemons


People also ask

How do you set limits in inputs?

To set the maximum character limit in input field, we use <input> maxlength attribute. This attribute is used to specify the maximum number of characters enters into the <input> element. To set the minimum character limit in input field, we use <input> minlength attribute.

How do you set the value of an input field in react?

To get the value of an input on button click in React: Declare a state variable that tracks the value of the input field. Add an onClick prop to a button element. When the button is clicked, update the state variable.


1 Answers

Try this:

var street = $(xml).find("address").find("street").text();

You were getting the node with .find("street"), but not its content, so you needed .text().

http://api.jquery.com/text/


EDIT:

You can check to see if a street node was found using the length property.

var street = $(xml).find("address").find("street");

alert(street.length); // should alert at least 1 if the find was successful
like image 63
user113716 Avatar answered Oct 06 '22 23:10

user113716