Reputation: 3734
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
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
Reputation: 55740
You are missing the document.ready function. try encasing your code in it.. Check this FIDDLE
Upvotes: 0
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
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
Reputation: 6384
Try this:
$("#test1").removeAttr("value")
This will do your job i guess.
Upvotes: 0