I’m trying to complete some ajax requests to insert a textarea into a database without refresh. Here is my code:
HTML:
JavaScript
x
3
1
<textarea name='Status'> </textarea>
2
<input type='button' onclick='UpdateStatus()' value='Status Update'>
3
JS:
JavaScript
1
13
13
1
function UpdateStatus(Status)
2
{
3
var Status = $(this).val();
4
5
$(function()
6
{
7
$.ajax({
8
url: 'Ajax/StatusUpdate.php?Status='.Status, data: "", dataType: 'json'
9
});
10
11
});
12
}
13
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
Advertisement
Answer
JavaScript
1
3
1
<textarea name='Status'> </textarea>
2
<input type='button' value='Status Update'>
3
You have few problems with your code like using .
for concatenation
Try this –
JavaScript
1
14
14
1
$(function () {
2
$('input').on('click', function () {
3
var Status = $(this).val();
4
$.ajax({
5
url: 'Ajax/StatusUpdate.php',
6
data: {
7
text: $("textarea[name=Status]").val(),
8
Status: Status
9
},
10
dataType : 'json'
11
});
12
});
13
});
14