WingMan20-10
WingMan20-10

Reputation: 3734

Clearing text input with jquery

I have an input field:

<input name="test1" class="t-input" id="test1" style="color: #fff;" type="text" value="3.05"/

I am trying to change the value or clear the value through jquery, I've tried all of these and none of them are working. The value changes, but I have to click on the textbox to see the change take effect. Am I missing something?

$('#test1').val('');
$('#test1').val("");
$('#test1').val("").change(); 
$('#test1').val("").trigger('change');
$('#test1').attr(value,'');

Upvotes: 0

Views: 162

Answers (5)

WingMan20-10
WingMan20-10

Reputation: 3734

Ok Got it!!

It is a text box being rendered using telerik mvc controls. So this is how you clear it.

$('#text1').data("tTextBox").value('');

Upvotes: 0

Sushanth --
Sushanth --

Reputation: 55740

You are missing the document.ready function. try encasing your code in it.. Check this FIDDLE

Upvotes: 0

Alain
Alain

Reputation: 36944

You should wait your page to be fully loaded ( ready in jquery ) to update your field :

<script type="text/javascript">

    $(document).ready(function () {
      $('#test1').val('');
    });

</script>

if that's not working, you probably need to read your Error Console (ctrl + shift + j on Firefox).

Upvotes: 2

Danil Speransky
Danil Speransky

Reputation: 30453

Maybe you try to work with it when dom is not built yet, try to use ready event handler:

$(document).ready(function () {
  // your code
});

Upvotes: 3

Paritosh Singh
Paritosh Singh

Reputation: 6384

Try this:

$("#test1").removeAttr("value")

This will do your job i guess.

Upvotes: 0

Related Questions