I have an ASP.NET user control that contains a textbox which has an AJAX CalendarExtender control which allows users to select a date which then populates the textbox.
I can clear the textbox value using a submit button and setting the value to null in the code behind, but I need to set the value to "" in the textbox using Javascript.
I have tried the following javascript but it didn't work:
function ClearTextBox()
{
document.getElementsByName('TextBox1').Value = "";
}
What javascript should I use?
Value
=> value
. JavaScript is case sensitive... getElementsByName
returns an array of elements so select the first element with [0]
document.getElementsByName('TextBox1')[0].value = "";
or select the element by id:
document.getElementById('TextBoxId').value = "";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.