On Feb 28, 2011, at 11:13 PM, Jason 'XenoPhage' Frisvold wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
I'm looking for some advice on how to update a specific field in a
table. Given the following table :
<table>
<tr>
<td>
<a href='#' onclick='editTags()'>Edit</a>
<input type='text' name='taglist[]' value='' />
</td>
</tr>
</table>
Assume for the moment that there are multiple rows and columns.
I've shown the column I'm interested in above. The editTags()
function looks like this :
function editTags() {
new Ajax.Request('feeds_ajax.php',
{
method: 'post',
parameters: {action: 'tagedit'},
onSuccess: function (transport) {
var json =
transport.responseText.evalJSON(true)
if (json.success == 'true') {
var editDiv = $('editDiv');
var blanketDiv = $('blanketDiv');
var blanket_height = blanket_size();
blanketDiv.style.height =
blanket_height + 'px';
popUpDiv_height = blanket_height / 2 -
150;
editDiv.style.top = popUpDiv_height +
'px';
var window_width = window_pos();
window_width = window_width / 2 - 150;
editDiv.style.left = window_width + 'px';
editDiv.innerHTML = json.output;
blanketDiv.style.display = 'block';
editDiv.style.display = 'block';
} else {
ajax_error(json.error);
}
},
onFailure: function() {
ajax_error('Server returned a failure');
}
})
}
This works as expected, displaying a CSS popup with the necessary
information in it. Basically it's a list of tags which can be
clicked and are placed into a textbox. When the user is done, they
click a button and the popup vanished. What's supposed to happen is
that the tags in the textbox are then transferred to the taglist
field in the table. It has to be the same row as the edit link that
was clicked, though. That's the part I'm having trouble with.
I've done some googling, but I guess I'm not hitting the correct
keywords. Can someone please assist?
Well, this would be easier and more Prototype-y if you used an event
listener instead of an onclick to open your function. If you did that,
you would have access to the Event.element() function, which would
give you an extended object reference to the element you clicked on.
From there it's very simple to update your input.
If you want to stick with the code the way you've written it, then
here's a simple change that you can use:
This line:
<a href='#' onclick='editTags()'>Edit</a>
becomes
<a href='#' onclick='editTags(this)'>Edit</a>
This line:
function editTags() {
becomes
function editTags(elm) {
var elm = $(elm);
And then, whenever you've come up with your list of tags, all you need
to do to to write the value back in is this:
elm.next('input').setValue(yourTagListAsText);
Walter
Thanks,
- ---------------------------
Jason 'XenoPhage' Frisvold
[email protected]
- ---------------------------
"Any sufficiently advanced magic is indistinguishable from
technology."
- - Niven's Inverse of Clarke's Third Law
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
iEYEARECAAYFAk1scm0ACgkQ8CjzPZyTUTR5lwCfXtJQW4f2WdHk+fKaBqZPQyZF
jUUAnjrePgHg8H4ApPl8qXJPzNCMwzYc
=bLtg
-----END PGP SIGNATURE-----
--
You received this message because you are subscribed to the Google
Groups "Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
.
To unsubscribe from this group, send email to [email protected]
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en
.
--
You received this message because you are subscribed to the Google Groups "Prototype
& script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en.