Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  54] [ 5]  / answers: 1 / hits: 165929  / 11 Years ago, sat, may 25, 2013, 12:00:00

I'm trying to complete some ajax requests to insert a textarea into a database without refresh. Here is my code:



HTML:



<textarea name='Status'> </textarea>
<input type='button' onclick='UpdateStatus()' value='Status Update'>


JS:



function UpdateStatus(Status)
{
var Status = $(this).val();

$(function()
{
$.ajax({
url: 'Ajax/StatusUpdate.php?Status='.Status, data: , dataType: 'json'
});

});
}


My Questions:



1) How do I send the contents of the text area into the onclick function?



2) How do I escape/urlencode etc.. So it retains line breaks


More From » jquery

 Answers
63
<textarea name='Status'> </textarea>
<input type='button' value='Status Update'>


You have few problems with your code like using . for concatenation



Try this -



$(function () {
$('input').on('click', function () {
var Status = $(this).val();
$.ajax({
url: 'Ajax/StatusUpdate.php',
data: {
text: $(textarea[name=Status]).val(),
Status: Status
},
dataType : 'json'
});
});
});

[#78024] Thursday, May 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jailynbethanies

Total Points: 686
Total Questions: 119
Total Answers: 99

Location: Cook Islands
Member since Thu, May 21, 2020
4 Years ago
;