I have some jQuery that uses AJAX and JSON to populate a UL tag with data.
This is the jQuery code:
$('#pSearch').on('click', function()
{
var partnername = $('#pNameSearch').val();
if($.trim(partnername) != '')
{
$.post('api/pNameSearch.php', {partnername: partnername}, function(data)
{
var obj = JSON.parse(data);
$('#pName').empty();
var htmlToInsert = obj.map(function (item)
{
return '<li>' + item.datestamp + ' - ' + item.comment + ' - ' + item.username + '</li>';
}).join('');
$('#pNames').html(htmlToInsert);
});
};
});
The code above populates a UL field called pNames. It fills LI tags with parsed JSON data retrieved from a PHP script.
What I need to do now is clear the pNames field.
In the search window that prints the data, I have an HTML RESET button.
<input type="reset" class="btn btn-sm btn-default" id="pReset" name="pReset" value="reset" />
Please note the TYPE in the input field, which I have set to 'reset', will clear out the FORM field, but it will not clear out the UL field that populated the data.
Here is the JavaScript I attempted to use to clear out the field:
$('#pReset').on('click', function ()
{
document.getElementById('#pName').val("");
});
What can I try next?