I have an jquery ajax call where I add a new comment to a database. It saves just fine but when i want to reaload the div where the comments are shown, I always get an additional div which I do not want. When I reaload the page everything is just fine and displayed as wanted!
The script:
<script>
$("#addcmt").click(function() {
var UserID = $("#UserID").val();
var ClassID = $("#ClassID").val();
var text = $("#appendedInputButton").val();
var option;
if($("#option").is(':checked')) {
option = 3;
} else {
option = 1;
}
$.ajax({
type: "GET",
url: "/comment/functions/add_class_comment.php",
data: "text=" + text + "&UserID=" + UserID + "&ClassID=" + ClassID + "&option=" + option,
success: function(msg) {
$("#CommentList").load(location.href+' #CommentList');
$('#appendedInputButton').val("");
$('.criticalcomment').attr('checked', false);
}
});
});
</script>
The php+html where they comments are shown:
<div class="bs-docs-example" id="message">
<div id="CommentList">
<?php
for ($i=0; $i<$l; $i++) {
switch($commentarr[$i]->getOption()) {
case 1:
$option="alert-success";
break;
case 2:
$option="alert-info";
break;
case 3:
$option="alert-error";
}
echo '<div class="Comments alert '.$option.'"><div class="CommentsName">'.$userarr[$i]->getFirstname().' '.$userarr[$i]->getLastname().'</div>';
echo '<div class="CommentsDate">'.renderDate($commentarr[$i]->getDate()).'</div><div class="CommentsText">'.$commentarr[$i]->getText().'</div>';
if ($deletebutton == 1) {
echo '<div class="deleteButtonAdmin"><input type="button" class="btn btn-small btn-primary delcmt" value="Löschen" name="'.$commentarr[$i]->getID().'"></div>';
}
echo '</div>';
}
?>
</div>
<form class="Comments postmessage">
<div class="input-append" style="margin-top: 10px;">
<input type="hidden" name="ClassID" id="ClassID" value="<?php echo $c->getID(); ?>">
<input type="hidden" name="UserID" id="UserID" value="<?php echo $u->getID(); ?>">
<textarea class="span12" name="text" id="appendedInputButton" type="text"></textarea>
<label for="option">Kritisch?</label><input type="checkbox" id="option" class="criticalcomment" name="option" value="1">
<input type="button" class="btn" id="addcmt" value="Post">
</div>
</form>
</div>
I hope someone got an idea or hint for me!
Well, $("#CommentList").load(location.href+' #CommentList'); tells jQuery to replace the contents of #CommentList with #CommentList, so you get two nested #CommentLists, correct?
You might have to do $("#CommentList").remove().load(location.href+' #CommentList'). If that does not work, try introducing a temporary div:
$("<div />").load(location.href+' #CommentList', function (div) {
$('#CommentList').replaceWith($(div));
})
try adding this after loading the div!
$("#CommentList").find('div').unwrap(); or
$("#CommentList").find('#CommentList').unwrap();//I am doubtful about this
Related
I used this script (https://www.webslesson.info/2020/02/instant-search-with-pagination-in-php-mysql-jquery-and-ajax.html) and I would like to add a form to directly access a page number.
I tried this but it doesn't work !
<div class="goto-page">
<form action="" method="POST" onsubmit="return pageValidation()">
<input type="submit" class="goto-button" value="Go to page">
<input type="text"
class="enter-page-no" maxlength="4" size="3"
name="goto" min="1"
required >
</form>
</div>
PHP Code modified
if (isset($_POST['goto'])) {
$start = (($_POST['page'] - 1) * $limit);
$page = $_POST['goto'];
}
else
{
if($_POST['page'] > 1)
{
$start = (($_POST['page'] - 1) * $limit);
$page = $_POST['page'];
}
else
{
$start = 0;
}
}
Consider the following example. This expands on the jQuery already in use in the example you linked to.
$(function() {
function load_data(page, query = '') {
$.ajax({
url: "fetch.php",
method: "POST",
data: {
page: page,
query: query
},
success: function(data) {
$('#dynamic_content').html(data);
}
});
}
load_data(1);
$(document).on('click', '.page-link', function() {
var page = $(this).data('page_number');
var query = $('#search_box').val();
load_data(page, query);
});
$('#search_box').keyup(function() {
var query = $('#search_box').val();
load_data(1, query);
});
$(".goto-page form").submit(function(evt) {
evt.preventDefault();
load_data(parseInt($(".goto-page input[name='goto']").val()));
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<br />
<div class="container">
<h3 align="center">Live Data Search with Pagination in PHP Mysql using Ajax</h3>
<br />
<div class="card">
<div class="card-header">Dynamic Data</div>
<div class="card-body">
<div class="form-group">
<input type="text" name="search_box" id="search_box" class="form-control" placeholder="Type your search query here" />
</div>
<div class="table-responsive" id="dynamic_content">
</div>
<div class="goto-page">
<form>
<button type="submit">Go To Page</button>
<input type="text" class="enter-page-no" maxlength="4" size="3" name="goto" value="1" required>
</form>
</div>
</div>
</div>
</div>
When Enter is hit or the Button pressed, the form is submitted. The submit callback will gather the value and use load_data() to load that page.
I have ajax based form submission and on success I want to show a success message. The elements are being generated dynamically by mysql results. Currently the success message for one shows up for all the elements in loop. How can I obtain this for that particular element. Some insight will be very helpful.
<?php if($row['section'] == 1) {?>
<ul class="list-group">
<li class="list-group-item active">
<div class="radio noMargin" id="<?php echo $sectionOne ; ?>info"><?php echo $no ; ?> <span class="glyphicon glyphicon-arrow-right"></span></div><?php echo "<font color='pink'>Ques ID :[".$row['id']."]</font>";?><div class="question"><?php echo $row['question'] ; ?></div>
<div style="float:right; margin-top:-20px;">
Marks:<?php echo $row['marks'] ; ?></div></li>
<?php
echo '<input type="hidden" name="question[]" id="questionId" value="'.$row['id'].'">';
echo '<input type="hidden" name="attempt" value="'.$attemptCount.'">';
echo '<input type="hidden" name="unit_id" value="'.$unit_id.'">';
echo '<input type="hidden" name="chapter_id" value="'.$chapter_id.'">';
$questionId = $row['id'] ;
$sqO =$db->query("SELECT id, options from tbl_options_mock_question WHERE question_id = ".$questionId."");
while($rowO=mysql_fetch_array($sqO))
{
?>
<li class="list-group-item wrp_radio">
<div class="radio noMargin">
<label>
<input disabled type="radio" class="checkedInfo" alt="<?php echo $no ; ?>" name="optionAns<?php echo $i ; ?>" value="<?php echo $rowO['id'] ; ?>">
<?php echo $rowO['options'] ; ?></label>
</div>
</li>
<?php } ?>
<div class="successMessage" style="display:none;"><font color="green"><b>Your notes for question is submitted successfully.</b></font></div>
<br>
<a class="click_notes" data-question-id="<?=$questionId?>"> <font size='2' color='blue'> Add Notes</font></a>
<br>
<div class="demo"></div>
</ul>
<?php $i++;$no++; ?>
<?php } ?>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.click_notes').on('click', function() {
var tid = $(this).data('question-id');
$(this).closest('ul').find('.demo').html('<div class="comment_form"><span><b>X</b></span><form id="contactForm1" action="submit.php" method="post"><textarea required cols="50" class="span10" name="notes" rows="6"></textarea><br><input class="btn btn-primary" id="submitnotes" name="submit_notes" type="submit" value="Add Notes"><input type="hidden" name="submitValue" value="' + tid + '" /></form><br></div>');
});
$(document).on('submit', '#contactForm1', function(e) {
e.preventDefault();
$.ajax({
type: this.method,
url: this.action,
data: $(this).serialize(),
success: function(data) {
$('.comment_form').hide();
$(".successMessage").show();
},
error: function(xhr) {
console.log('An error occurred.');
console.log(xhr);
},
});
}).on('click', 'span', function() {
$(this).parent().hide()
});
});
</script>
Here is a Fiddle I used for testing: https://jsfiddle.net/Twisty/gokfth37/41/
HTML
<ul class="list-group">
<li class="list-group-item active">
<div class="radio noMargin" id="section-1-info">
1
<span class="glyphicon glyphicon-arrow-right"></span>
</div>
<font color='pink'>Ques ID : 1</font>
<div class="question">
Question 1
</div>
<div style="float:right; margin-top:-20px;">Marks: Marks 1
</div>
</li>
<li>
<input type="hidden" name="question[]" id="questionId" value="1">
<input type="hidden" name="attempt" value="0">
<input type="hidden" name="unit_id" value="1">
<input type="hidden" name="chapter_id" value="1">
</li>
<li class="list-group-item wrp_radio">
<div class="radio noMargin">
<input disabled type="radio" class="checkedInfo" alt="1" name="optionAns1" value="1">
<label>Answer 1</label>
<input disabled type="radio" class="checkedInfo" alt="2" name="optionAns2" value="2">
<label>Answer 2</label>
<input disabled type="radio" class="checkedInfo" alt="3" name="optionAns3" value="3">
<label>Answer 3</label>
</div>
</li>
<li>
<div class="successMessage" style="display:none;">
<font color="green">
<b>Your notes for question is submitted successfully.</b>
</font>
</div>
<br>
<a class="click_notes" data-question-id="1">
<font size='2' color='blue'>
Add Notes
</font>
</a>
<br>
<div class="demo">
</div>
</li>
</ul>
I made some leaps and created HTML based on the PHP code you had. You can see here that I had to correct a lot of HTML Syntax. You should not have <ul> that have <input> or <div> elements as children. It should only be <li> elements that can then contain other elements.
So when the "Add Notes" button is clicked, a form is dynamically created that must have a unique ID and all the elements within must have unique IDs. This form will have a Close button, a Text Area, a hidden element and a submit button. When the form is submitted, the data from the form should be submitted via POST to a specific URL and upon successful submission, display the success note.
JavaScript
$(function() {
$('.click_notes').on('click', function() {
$(this).parent().find(".successMessage").hide();
$(this).hide();
var that = $(this);
var tid = $(this).data('question-id');
var form = $("<form>", {
id: "contact-form-" + tid,
action: "submit.php",
method: "POST",
class: "comment-form"
}).submit(function(e) {
e.preventDefault();
$.ajax({
type: $(this).attr("method"),
url: $(this).attr("action"),
data: $(this).serialize(),
success: function(data) {
console.log("Success");
$('.comment-form').hide();
that.parent().find(".successMessage").show();
that.show();
},
error: function(xhr) {
console.log('An error occurred.');
console.log(xhr);
}
});
});
$("<span>", {
class: "close btn"
}).html("X").click(function() {
that.show();
$(this).parent().hide();
}).appendTo(form);
$("<textarea>", {
required: true,
cols: "50",
class: "span10",
name: "notes"
}).appendTo(form);
$("<input>", {
type: "hidden",
name: "submitValue",
value: tid
}).appendTo(form);
$("<button>", {
class: "btn btn-primary",
id: "submit-notes-" + tid,
type: "submit"
}).html("Add Notes").appendTo(form);
$(this).closest('li').find('.demo').html(form);
});
});
One of the benefits of creating content with jQuery is that you can bind callbacks when you create the object. So instead of mucking around with .on() you can also just call .click() or .submit() right when you're creating the objects. Either works, but sometimes one is easier to manage than the other.
In the example above, we create the form, bind a submit callback to it, add other elements, and the replace #demo with this newly created content. I also added some extra bits to hide a few things, if they are being shown.
When you see var that = $(this); it's sort of a little trick since we do not want to confuse this in some of the other callbacks, yet we may need to reference the original this, and we can, using that.
Hope this helps.
I suggested moving the message outside the loop so you only have ONE message. You could even show it in a dialog
Also you have more than one jQuery loaded. Just load latest or 3.x, not both
change id="contactForm" to class="contactForm"
The HTML is invalid. Move the </ul> to before the demo div
It would have been easier if you wrapped each question and demo div in a wrapper, but try this:
$(document).on('submit', '.contactForm', function(e) {
e.preventDefault();
var $currentForm = $(this);
...
success: function(data) {
$currentForm.hide();
$currentForm.prevAll(".successMessage:first").show();
},
I have a form in PHP & MySQL and I want to submit it with AJAX.
I Have similar data so I have put these data in a foreach loop.
The problem is that when I try to submit the first row data it all goes well but it changes the data in all rows. and when I try to submit other data except the first row it doesn't submit at all.
I think the problem is because the submit button always gets the same id and therefore goes to the first row always.
I don't know how to get the value in Ajax.
Here goes the code:
//php form
<?php
$pid = $_GET['pid'];
include('config.php');
$timeline_query="SELECT * FROM timeline_table WHERE pid=$pid";
$result_timeline=mysqli_query($conn,$timeline_query);
if(!$result_timeline){
echo "Error: " . $conn->error;
}
$timelines=array();
while($row_timeline=mysqli_fetch_assoc($result_timeline)){
$timelines[]=$row_timeline;
}
?>
<?php
$x = 0;
foreach ($timelines as $timeline):?>
<div class="card">
<div class="card-header" id="heading<?php echo $x; ?>">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapse<?php echo $x; ?>" aria-expanded="true" aria-controls="collapse<?php echo $x; ?>">
<?php echo $timeline['timeline_title'];?>
</button>
</h5>
</div>
<div id="collapse<?php echo $x; ?>" class="collapse" aria-labelledby="heading<?php echo $x; ?>" data-parent="#accordion">
<div class="card-body">
<form id="register_form">
<input type="text" id="tid" name="tid" value="<?php echo $timeline['tid']; ?>"/>
<textarea class="form-control" rows="4" id="timeline_description" name="timeline_description"><?php echo $timeline['timeline_description'];?></textarea>
<input id="submit" type="submit" name="submit" value="Submit" />
</form>
</div>
</div>
</div>
<?php $x++; endforeach;
// ajax function
$(document).ready(function(){
$("#submit").click(function(){
var timeline_description = $("#timeline_description").val();
var tid = $("#tid").val();
alert(timeline_description);
alert(tid);
// Returns successful data submission message when the entered information is stored in database.
// var dataString = 'timeline_description='+timeline_description+'&pid='+ pid + '&tid='+ tid +;
var dataString = 'timeline_description='+timeline_description;
alert(dataString);
if(timeline_description=='')
{
alert("Please Fill All Fields");
}
else
{
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "process.php?tid"=+tid,
data: dataString,
cache: false,
success: function(result){
alert(result);
}
});
}
return false;
});
});
//process.php
<?php
include('config.php');
$tid=$_GET['tid'];
if( $_POST['timeline_description']==NULL ){ $timeline_description=''; }
else { $timeline_description=$_POST['timeline_description']; }
$query_timeline = "UPDATE timeline_table SET
timeline_description='$timeline_description' WHERE tid=$tid ";
$result=mysqli_query($conn,$query_timeline);
if(!$result){
echo "Error: " . $conn->error;
}
?>
Any idea?
Id of elements must be unique. The abnormal behaviour of your code is due to non-unique ids of your input elements.
In the case, If you cannot assign unique ids to elements you can achieve desired output by using this keyword and siblings() method in jquery.
Instead of
var timeline_description = $("#timeline_description").val();
var pid = $("#pid").val();
var tid = $("#tid").val();
try to get values in this way.
var timeline_description = $(this).siblings('#timeline_description').val();
var pid = $(this).siblings('#pid').val();
var tid = $(this).siblings('#tid').val();
I see there a problem with Yours inputs id - <input type="text" id="pid" - this is in foreach, so You have multiple elements with same id. So var pid = $("#pid").val(); will return You always a value of first found element. Try to use arrays:
<input type="text" id="pid[$pid]" name="pid[$pid]" value="<?php echo $pid ?>"/>
<input type="text" id="tid[$pid]" name="tid[$pid]" value="<?php echo $timeline['tid']; ?>"/>
Please remember one thing: id of any element in html PAGE (whole document) must be unique.
I have a custom dropdown. Want to change the value of the button as selected option of dropdown
list.
This is my view code. I tried with jquery but unsuccessfull.
Please some one help me with jquery
<div class="col-md-5 col-sm-6">
<div class="form-group droplist">
<label for="project_category">project Categary</label><br/>
<input type="button" class="form-control" id="relig" value="<?php if(isset($projectDetails->project_category) && !empty($projectDetails->project_category)){
echo #$projectDetails->project_category;
}else{
echo "select Category";
}?>">
<div id="religions" class="dropdownmenu" style="display:none;padding-left:17px">
<?php foreach($categories as $cat){ ?>
<div id="<?php echo $cat['code'] ?>" class="maincategory">
<label><input type="radio" class="category" name="project_category" id="category" value="<?php echo $cat['code'] ?>"> <?php echo $cat['Project_classification_id']." - ".$cat['Description'] ?></label><br/>
</div>
<?php } ?>
</div>
</div>
</div>
I have above 140 dropdown values for that i used foreach, notonly 3 values
This is my jquery. I done all thing but unable to show the checked radio value as button value(title)
$('#relig').click(function(){
$('#religions').slideToggle("fast");
});
traversed_ids = [];
$(document).on('change','.project_category',function() {
maincat = $(".project_category:checked").val();
if ($.inArray(maincat, traversed_ids) < 0) { //check element exist in array or not
traversed_ids.push(maincat); //add element to array
changeCategoryList(maincat); //call ajax
}
});
function changeCategoryList(maincategory){
$.ajax({
url: '<?php echo site_url("abcd/xyz"); ?>',
type: 'POST',
data: { maincategory:maincategory },
dataType: 'json',
success: function(data) {
$.each(data, function(key, value) {
var MoreTag='';
MoreTag += '<div id="'+value.code+'" Style="padding-left:20px" class="subcategory">';
MoreTag += '<label ><input type="radio" class="project_category" name="project_category" id="project_category" value="'+value.code+'"> '+value.Project_classification_id+' - '+value.Description+'</label><br/>';
MoreTag += '</div>';
$("#"+maincategory).append(MoreTag);
});
}
});
}
$(".maincategory").click(function (e) {
e.stopPropagation(); //to stop event bubbling
if ($(this).children('.subcategory').is(':checked')) { //check if hidden or not
$(this).children('.subcategory').hide(); //if yes hide
} else {
$('.maincategory').children('.subcategory').hide();
$(this).children('.subcategory').show(); // else show
}
});
I have made sample example as per my understanding from your question.
Please check below example.
$(document).on('change','input[name="rgroup"]',function() {
radio = $("input[name='rgroup']:checked").val();
$("#btn").val(radio);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" name="rgroup" value="test1">Test1
<input type="radio" name="rgroup" value="test2">Test2
<input type="radio" name="rgroup" value="test3">Test3
<input type="radio" name="rgroup" value="test4">Test4
<br>
<input type="button" id="btn" value="Change">
I using AJAX and generate html code with PHP after I get answer from the DATABASE.
first part work greate, I am laoding data from the Data base and and create table of forms.
the issue is that I can't edit the use the IDs that create I tried to change TD size or call specific IDs with JQuery but nothing happen.
HTML
<html>
<head>
<title>תמונה במתנה</title>
<meta charset="utf-8">
<link href="admin-style.css" rel="stylesheet" type="text/css">
<script src="jquery.js"></script>
<script src="admin.js"></script>
</head>
<body>
<div id="container">
<div id="customer-list">
</div>
<button type="button" id="loadbtn">טען</button>
<div id="search">
<form id="searchForm" action="admin.php" method="post">
שם פרטי:<input type="text" name="fname" id="fname">שם:
שם משפחה:<input type="text" name="lname" id="lname">
טלפון:<input type="text" name="phone" id="phone">
אימייל:<input type="text" name="email" id="email">
<input id="searchForm" type="submit" name="searchbtn" value="חפש" />
</form>
</div>
<div id="serchList">
</div>
<div id="editCustomer">
</div>
</div>
</body>
</html>
JQuery:
$(document).ready(function() {
$.ajax({
url: 'loadClient.php?submit=load',
success: function(data){
$('#customer-list').html(data);
}
}).error(function(){
alert('an alert occored');
}).success(function(){
// alert('success');
}).complete(function(){
// alert('complete');
});
$
$("#savebtn").click(function(){
alert ('hi)';
var lfname=document.getElementById('lfname').value;
var llname=document.getElementById('llname').value;;
var lemail=document.getElementById('lemail').value;;
var lcity=document.getElementById('lcity').value;;
var lphotos=document.getElementById('lphotos').value;;
var lid=document.getElementById('lid').value;;
$.ajax({
type:'POST',
url: 'loadClient.php ',
data: 'submit=save&lfname='+lfname+'&llname='+llname+'&lemail='+lemail+'&lcity='+lcity+'&lphotos='+lphotos+'&lid='+lid,
success: function(data){
$('#customer-list').html(data);
}
}).error(function(){
alert('an alert occored');
}).success(function(){
// alert('success');
}).complete(function(){
// alert('complete');
});
$.ajax({
url: 'loadClient.php?submit=load',
success: function(data){
$('#customer-list').html(data);
}
}).error(function(){
alert('an alert occored');
}).success(function(){
// alert('success');
}).complete(function(){
// alert('complete');
});
});
PHP
echo '<table border=1 cellspacing="0" cellpadding="0">';
echo '<tr>';
echo '<td width="80px">שם פרטי</td>';
echo '<td>שם משפחה</td>';
echo '<td>טלפון</td>';
echo '<td>אימייל</td>';
echo '<td>עיר</td>';
echo '<td width="150px">שעת רישום</td>';
echo '<td>מספרי תמונות</td>';
echo '<td>שמור</td>';
echo '</tr>';
$loadQuery="SELECT * FROM `claients` WHERE `eventreg_pictures` is null
OR `eventreg_pictures` like ''";
$result=mysql_query($loadQuery);
while($row= mysql_fetch_array($result)){
$client= $row;
$clients[]=$client;
echo '<tr>';
echo '<form id="loadForm" method="post" action="admin1.php">';
echo '<input type="hidden" name="lid" value="'.$client[0].'">';
echo '<td><input type="text" id="lfname" name="lfname" value="'.$client[1].'"></td>';
echo '<td><input type="text" id="llname" name="llname" value="'.$client[2].'"></td>';
echo '<td><input type="text" id="lphone" name="lphone" value="'.$client[3].'"></td>';
echo '<td><input type="text" id="lemail" name="lemail" value="'.$client[4].'"></td>';
echo '<td><input type="text" id="lcity" name="lcity" value="'.$client[5].'"></td>';
echo '<td>'.$client[7].'</td>';
echo '<td><input type="text" id="lphotos" name="lphotos"></td>';
echo '<td><input type="submit" id="savebtn" name="savebtn" value="שמור"></td>';
echo '</form>';
echo '</tr>';
}
echo '</table>';
}else echo'error';
If I'm right, the problem is that Your #savebtn doesn't exist when You define the $("#savebtn").click handler.
Try this instead:
$("#savebtn").ready(function(){
$("#savebtn").click(function() //...Continue Your code...
});
A few things:
'1. You're mixing up jQuery and javascript, when jQuery is simpler and shorter to type. This line:
`var lfname=document.getElementById('lfname').value;`
can be replaced with this line:
var lfname=$('#lfname').val();
'2. Your PHP is looping through results returned by a mysql search, but you are using the same ID for all returned rows. This is a no-no. Each ID must be unique. Edit your PHP code to add a unique number to each id name, based on row.
Try Something like:
$counter = 0;
$loadQuery="SELECT * FROM `claients` WHERE `eventreg_pictures` is null
OR `eventreg_pictures` like ''";
$result=mysql_query($loadQuery);
while($row= mysql_fetch_array($result)){
$client= $row;
$clients[]=$client;
echo '<tr>';
echo '<form id="loadForm-' .$counter. '" method="post" action="admin1.php">';
echo '<input type="hidden" name="lid" value="'.$client[0].'">';
echo '<td><input type="text" id="lfname-' .$counter. '" name="lfname" value="'.$client[1].'"></td>';
That way, in your jQuery, you can check to see - for example - which field was just completed:
$('[id^=lfname]').blur(function() {
var xx = $(this).attr('id');
alert('You edited input: ' + xx);
var arrYY = xx.split('-'); //turn xx into an array, separated at each hyphen
var yy = arrYY[1]; //The number part of the array
alert('The number part of this element is: [' +yy+ ']');
});
'3. Note that you can also select elements by class, so you could add a class to your lfname input fields, catch the blur (or focus, or etc) event on any element with that class, and determine exactly which input it was:
echo '<td><input type="text" id="lfname-' .$counter. '" name="lfname" value="'.$client[1].'"></td>';
$('.lfname').blur(function() {
var xx = $(this).attr('id');
alert('You edited input: ' + xx);
});
'4. To be clear, the reason nothing happens when you reference specific IDs on your page is because you have more than one element with that same ID. IDs must be unique. See #2 above to make the IDs unique, or just use the class attribute.
שלם