Reputation: 277
I am new to Jquery I am trying to save entered value in
My structure is Like this
<td><input type="text" class="txtbox" value="" /></td>
Now when user enter value in first tr and click on save that time that value will show in respective td and should not be editable and button of save will change to Edit button
here is jsfiddle
http://jsfiddle.net/nikkirs/0qjsag8h/
Upvotes: 1
Views: 280
Reputation: 15923
Just change this function as:
$("#savebtn").click(function(){
if($(this).val()=="Edit")
{
this.value = 'Save';
$(this).closest("tr").find('input[type=text]').each(function(){
$(this).removeAttr("disabled");
});}
else{ if ($('.test tr:last input:text[value]').length == 0) {
alert("FAIL - all textboxes on last row are empty.");
}
else { $(this).closest("tr").find('input[type=text]').each(function(){
$(this).attr("disabled","");
});
alert('SUCCESS - at least 1 value is filled in!');
this.value = 'Edit';
}
}
});
Now once you clicked save you wont be able to edit the values. You can do this only after clicking the edit button.
Upvotes: 0
Reputation: 82241
You need to iterate over all the td element in currently clicked rows save button and set each tds text/html:
$("#savebtn").click(function(){
if ($('.test tr:last input:text[value]').length == 0) {
alert("FAIL - all textboxes on last row are empty.");
}
else {
alert('SUCCESS - at least 1 value is filled in!');
this.value = 'Edit';
$(this).parent().siblings().each(function(){
$(this).text($(this).find('input').val())
});
}
});
Upvotes: 1