I want to create a form that allows users to enter comments about a currently playing song. I want to pass the “song_id” and textarea input to AJAX for further processing (calling a php file that updates mysql).
So far I have an ajax function
function doComments( song_id, comments )
{
new Ajax.Request('comments.php',
{
method:'post',
parameters: {fhr_time: getFHRTime(), id: song_id, comments: comments},
onSuccess: function(transport)
{
var response = transport.responseText || "no response";
new Effect.Fade( "song_comments",
{ afterFinish: function ()
{
document.getElementById( "song_comments" ).innerHTML = response;
new Effect.Appear( "song_comments" );
}
});
}
});
}
I dont need help on the comments.php but I do need help with the form on my main page.
<form name="theForm" method="post" action="javascript:doComments(<?php echo $now_playing["song_id"]; ?>, <?php echo $comments; ?> );">
<TEXTAREA type="text" name="comments" ROWS="5" COLS="50"></TEXTAREA>
<br>
<font face="Verdana, Arial, Helvetica" size="1">
Maximum comment is 200 characters
</font>
<br>
<input type="submit" name="button1" value="Submit Comment">
<input type="button" name="button2" value="Check length" onclick="javascript:alert('Comment length:\
' + document.theForm.comments.value.length + ' character(s)');">
</form>
I am trying to pass “song_id” and “comments” to AJAX that in turn calls comments.php. song_id gets passed but comments do not.
I have tried many variations also trying onclick instead of form action, but nothing seems to work for me.