Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a form and upon filling it out, I want the data to be inserted into a database. As of now, the database has two columns, "feedback" and "date". But right now, only the "date" gets inserted into the database, not the "feedback".

HTML Form:

<form class="form-inline" action="JavaScript:sendFeedback()" method="get">
<textarea name="Feedback" placeholder="Feedback..." rows="5" cols="100"></textarea> 
<button type="submit" class="btn">Tell us</button>
</form>

Javascript:

function sendFeedback() {
    _gaq.push(['_trackPageview', 'OutgoingLink=SendFeedback' ]);
    $.get("../php/NewFeedback.php",{Feedback:$('input[name="Feedback"]').val()});
    var element = document.getElementById("FeedbackArea");
    element.innerHTML = "<div class=\"alert alert-success\"> <a class=\"close\" data-dismiss=\"alert\" href=\"#\">×</a>Thanks for your feedback!</div>";
    return false;
}

php:

$db = MySql::getInstance(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
$Feedback = mysql_real_escape_string($_GET['Feedback']);

//create the sql statement
$sql = "INSERT INTO Feedback VALUES('{$Feedback}', CURDATE());";

//execute the query
$res = $db->query($sql);

And like I said, if I type something to the textarea and press the button "Tell us", the Database gets a new entry, but the "Feedback" attribute is empty (and the date is filled in).

Why is this?

share|improve this question
    
Change the selector to $('textarea[name="Feedback"]').val() –  Arjun Abhynav Dec 29 '12 at 18:17

2 Answers 2

up vote 1 down vote accepted

You don't have an input named Feedback, you have a textarea so $('input[name="Feedback"]').val() won't give you the value of the field.

share|improve this answer
    
Okay so how do I fix this? Why did you give me a downvote... –  CodeGuy Dec 29 '12 at 18:10
    
You change your selector to match textarea elements instead of input elements –  Quentin Dec 29 '12 at 18:10
    
Thanks. That worked. –  CodeGuy Dec 29 '12 at 18:11

Change your code:

$('textarea[name="Feedback"]').val()

And it will work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.