how to set textbox value to empty(blank) using javascript
assuming the element you want to change has the id 'question' you can do
document.getElementById("question").value = "";
another example if
var doc_val_check = $('#doc_title').attr("value");
if (doc_val_check.length > 0) {
doc_val_check == "";
}
doc_val_check == ""; // == is equality check operator
should bedoc_val_check = ""; // = is assign operator. you need to set empty value
// so you need =
You can write you full code like this:var doc_val_check = $.trim( $('#doc_title').val() ); // take value of text
// field using .val()
if (doc_val_check.length) {
doc_val_check = ""; // this will not update your text field
}
To update you text field with a ""
you need to try$('#doc_title').attr('value', doc_val_check);
// or
$('doc_title').val(doc_val_check);
But I think you don't need above process.In short, just one line
$('#doc_title').val("");
Note
.val()
use to set/ get value in text field. With parameter it acts as setter and without parameter acts as getter.
Comments
Post a Comment