I have a list of messages with element ids as "message"+id ( message1, message2 etc) when user makes ajax request from any particular message i want to access only the id. should i strip the id from the message id in jquery before submitting or do it on the server side? Or is there a simpler way to represent the id on the webpage for each message?
You can attach the message ID as an attribute to the DOM element itself. In mootools it is
Elm.set('messageId',12);//12 is an arbitrary message id I chose for this example.
//get it
alert(Elm.get('messageId'));
I am 100% sure in JQuery there is something very similar. But, striping the id itself, using JS, from a string with a pre-known format ain't that hard.
The user has to click something, right? If it's a link, I'd put the id somewhere in the onclick function call; if it's a button, same deal with a hidden form input. That you're doing this all with jQuery makes it all easier, but doesn't particularly matter.
Depending on how the rest of your page works you could wrap each element in a form tag and use a hidden field for the id. Potentially, doing this in conjunction with the jquery forms plugin (http://www.malsup.com/jquery/form/) could save you some development effort overall.
Adding attributes to the dom will also work of course as long as you aren't concerned about putting non-compliant attributes in there.
In any case, I'd definitely recommend sending an id value to the server in your ajax request rather than stripping the value out of a string on the server. This is cleaner and better from a separation of concerns perspective.