I understand this is an easy question but for some reason this just isn\'t working for me. I have a function that is triggered everytime a drop down menu is changed. Here
In simple way, you can use the following code to clear all the text field, textarea, dropdown, radio button, checkbox in a form.
function reset(){
$('input[type=text]').val('');
$('#textarea').val('');
$('input[type=select]').val('');
$('input[type=radio]').val('');
$('input[type=checkbox]').val('');
}
First Name: <input type="text" autocomplete="off" name="input1"/> <br/> Last Name: <input type="text" autocomplete="off" name="input2"/> <br/> <input type="submit" value="Submit" /> </form>
Try using this :
function checkValue(){
var value = $('#doc_title').val();
if (value.length > 0) {
$('#doc_title').val("");
$('#doc_title').focus(); // To focus the input
}
else{
//do something
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<input type="text" id="doc_title" value="Sample text"/>
<button onclick="checkValue()">Check Value</button>
</body>
You are comparing doc_val_check
with an empty string. You want to assign the empty string to doc_val_check
so it should be this:
doc_val_check = "";
For the most part you just set the .val() method. All of the answers are pretty accurate, just wanted to post my results to anyone who may need to set the value via the client id that gets rendered.
$('#' + '<%= doc_title.ClientID %>').val(null);
Instead of all those:
$('#doc_title').attr("value", "");