I still have some problems with jQuery. If I have html like this:
<form method="post">
<textarea id="id_content" rows="10" cols="40" name="content"></textarea>
<input id="yes" type="submit" value="submit">
</form>
<form method="post">
<textarea id="id_content" rows="10" cols="40" name="content"></textarea>
<input id="no" type="submit" value="submit">
</form>
<form method="post">
<textarea id="id_content" rows="10" cols="40" name="content"></textarea>
<input id="question" type="submit" value="submit">
</form>
Why can’t I successfully post a request with this jQuery code?
$(function(){
$('input').live('click', function(){
if ($(this).attr('id') == 'yes'){
var url = 'www.example.com/add_yes/'
} if ($(this).attr('id') == 'no'){
var url = 'www.example.com/add_no/'
} else {
var url = 'www.example.com/add_question/'}
var form = $('.' + $(this).attr('id'))
var textarea = form.$('texarea[name="content"]').text().serialize()
$.ajax({
type: 'POST',
url: url,
data: textarea,
success: succes,
dataType: 'json'
})})})
And here is this code in jsfiddle http://jsfiddle.net/
Give a unique class to all of your text area i am using class = ‘content ‘
Then use this jquery code , this will solve your problem