I have already figured out how to replace a button with jquery and ajax like this:
$("#addButton").hide();
$('.form').show();
But on another page I display multiple submit buttons that each submit different data to a database, and I don’t know how to keep track of which button is which so that when clicked only that button disappears?
The page is created dynamically based on a search result so I have a different amount of buttons each time. I tried passing a variable for the name of an element but did not know how to then use that variable in the jquery call?
If you all have any ideas about how I can go about accomplishing this, I would appreciate it.
Update:
Here is the form being created that displays the search results and a form to click a button to send a friend request.
for($i = 0; $i<$numF;$i++){
$row = $resultF->fetch_assoc();
$friendName = $row['userName'];
$friendID = $row['userID'];
print "
<p> $friendName </p>
<form method = \"post\" action = \"\" onsubmit = \" return addFriend('$userID','$user','$friendName', '$friendID')\" >
<input type = \"submit\" value = \"Send friend Request\" />
</form>
<hr>
";
}
Also here is the function being called:
function addFriend(userID,user,friendName, friendID)
{
//run ajax
var ajaxSettings = {
type: "GET",
url: "friendRequest.php",
data: "uID="+userID+"&uName="+user+"&fName="+friendName+"&fID="+friendID,
error: function(xhr, status, error) { alert("error: " + error); } };
$.ajax(ajaxSettings);
return false;
}
You can refer to which button was clicked using
this:Will hide the clicked button. Other than that, I don’t know how to help you because you didn’t supply enough information.