JSFiddle - React, Tailwind, and code Playground
HTML
<div id="searchParameters">
<table>
<tr>
<td class="clsLabel">Account Number</td>
<td style="border: 0px;"><input id="gioId" type="text" name="gioId">
<td class="clsLabel">User Bank ID</td>
<td style="border: 0px;"><select style="font-size: 12px;" name="userBank" id="userBank">
<option value="DV">DV</option>
<option value="SD">SD</option>
<option value="NT">NT</option>
<option value="IR">IR</option>
<option value="AU">AU</option>
</select></td>
</tr>
<tr>
<td style="border: 0px;"></td>
<td style="float: right; border: 0px;"><input type="button"
class="btn" value="Search" onclick="tlmSearch('searchParameters')">
<input type="button" class="btn btn-primary" value="Clear"
onclick="refresh()"></td>
</tr>
</table>
</div>
JavaScript
function tlmSearch(formId){
var formName = "#"+formId;
var url = "searchTlm"
var postData="";
var accNumVal = $.trim($(formName).find('#gioId').val());
if(accNumVal=="" && accNumVal.length==0){
accNumVal = null
}
if(accNumVal != null){
if(isNaN(accNumVal)==true){
alert("Account Number should be Numeric");
return false;
}
}
// else{
$(formName +' input').each( function(){
var value ='';
value = $(this).val();
if(value !== "Search" || value !== "Clear"){
if(value === "gioId"){
value = value.valueOf();
}
value = (value) ? $.trim(value) :'';
postData = "'"+$(this).attr('name')+"':'"+value+"' ,"+postData;
alert("Post data values 2: " +postData);
}
});
//handle select parameters
$(formName+ ' select').each( function(){
var value = $(this).val();
value = (value) ? $.trim(value) :'';
postData = "'"+$(this).attr('name')+"':'"+value+"' ,"+postData;
});
//json parsing
postData = eval('( {'+postData.substring(0, postData.length-1)+'} )');
//alert(postData);
//Ajax Call
$.post(url,postData,function(data){
//alert('Data Posted Successfully');
var newDoc = document.open("text/html", "replace");
newDoc.write(data);
newDoc.close();
})
.fail(function(response) {
$('#error').empty().append("Unable to Search Records")
$('#error').show();
});
// }
}