Joshua Akande Joshua Akande - 1 month ago 7
Javascript Question

How to introduce a click event in ajax

this already works for onchange just for the input field only btu
i'm trying to make the ajax work when the search button is clicked
the url calls the php side which is in perfect condition



<script type="text/javascript">
function bn(val)
{
$.ajax({
type: 'post',
url: 'salprefix.php',
data: {
submitname:val
},
success: function (response) {
document.getElementById("submitname").innerHTML=response;
}
});


}
</script>
</head>
<body>
<form method='post' action='#'>
<table>
<tr>
<td>
<label for='name'>Name</label>
</td>
<td>
<input type='text' id='staffname' name='staffname' onchange='bn(this.value);'>
</td>
</tr>
<tr>
<td colspan='2'>
<input type='submit' id='submit' name='submit' value='Search'>
</td>
</tr>
</table>
</form>
<div id = 'submitname'></div>
</body>



Answer
<input type='button' id='submit' name='submit' value='Search' onclick="bn(staffname.value)">

try this