I’m trying to implement in-line editing of table data that is generated via php.
Here’s the php code that generates a row
<tr class="zipCodeRow">
<td>
<a class="hideOnEdit zipCodeFormSubmit" name="' . $rowZipCodes['id'] . '" href="#">Edit</a>
<input type="submit" class="hideOnLoad submitEditZipCodeRow zipCodeFormSubmit" id="submitEditZipCodeRow-' . $rowZipCodes['id'] . '" value="Save Edits" /><br />
<input type="submit" class="hideOnLoad cancelEditZipCodeRow zipCodeFormSubmit" value="Cancel Edit" />
</td>
<td>
<input type="checkbox" class="chkDeleteZipCodeRow zipCodeFormSubmit" name="deleteZipCodeRow[]" value"' . $rowZipCodes['id'] . '" />
</td>
<td>
<label class="hideOnEdit">' . $rowZipCodes['state'] . '</label>
<input type="text" class="hideOnLoad" size="20" maxlength="50" value="' . $rowZipCodes['state'] . '"
</td>
<td>
<label class="hideOnEdit">' . $rowZipCodes['county'] . '</label>
<input type="text" class="hideOnLoad" size="15" maxlength="50" value="' . $rowZipCodes['county'] . '"
</td>
<td>
<label class="hideOnEdit">' . $rowZipCodes['city'] . '</label>
<input type="text" class="hideOnLoad" size="20" maxlength="50" value="' . $rowZipCodes['city'] . '"
</td>
<td>
<label class="hideOnEdit">' . $rowZipCodes['zipCodes'] . '</label>
<textarea class="hideOnLoad">' . $rowZipCodes['zipCodes'] . '</textarea>
</td>
You can see by the classes that I want certain elements to hide on page load and those elements will be shown on Edit. This line of jQuery properly hides the “hideOnLoad” classes elements:
$('.hideOnLoad').hide();
Then, I have javascript to detect when the Edit link is clicked and I call this function:
function EditTableRow(linkClicked) {
var id = linkClicked.attr('name');
$('a.hideOnEdit').fadeOut(500);
$('input.hideOnEdit').fadeOut(500);
$('textarea.hideOnEdit').fadeOut(500);
$('input.hideOnLoad').fadeIn(500);
$('textarea.hideOnLoad').fadeIn(500);
}
I knew as soon as I wrote the function that it didn’t seem right, but I’m not sure how to implement what I need to do.
I’d appreciate anyone’s suggestions on how to make this work as described!
First thing’s first, you don’t want to call
$('.hideOnLoad').hide();when the page loads. You run the risk of the user seeing the fields for a brief period. Instead add the following CSS. This is more likely to take effect before the user sees anything (but not guaranteed unless it’s inline).As for your
EditTableRowmethod, you’re running it on everything rather than within the scope of the given row. Try something like this: