Skip to content Skip to sidebar Skip to footer

Reset Textbox Value In Javascript

If I have a input textbox like this: How can I set the value of the textfield using javascript or jQuery? You would

Solution 1:

In Javascript :

document.getElementById('searchField').value = '';

In jQuery :

$('#searchField').val('');

That should do it


Solution 2:

Use it like this:

$("#searchField").focus(function() {
    $(this).val("");
});

It has to work. Otherwise it probably never gets focused.


Solution 3:

To set value

 $('#searchField').val('your_value');

to retrieve value

$('#searchField').val();

Solution 4:

I know this is an old post, but this may help clarify:

$('#searchField')
    .val('')// [property value] e.g. what is visible / will be submitted
    .attr('value', '');// [attribute value] e.g. <input value="preset" ...

Changing [attribute value] has no effect if there is a [property value]. (user || js altered input)


Solution 5:

Try using this:

$('#searchField').val('');

Post a Comment for "Reset Textbox Value In Javascript"