I have this really basic HTML page:
<textarea id='carmodeldescription' name="carmodeldescription"></textarea>
<br/>
<button id='#booboo'>button</button>
And this jQuery:
$('#booboo').click(function(e){
e.PreventDefault;
var texttosubmit = $('#carmodeldescription').html();
alert(texttosubmit);
return false;
});
When I type something in the <textarea> and click the button, it alert()s an empty string.
But, if after e.PreventDefault; I put this line of code:
$("#carmodeldescription").html('texttosubmit');
It works (adds ‘texttosubmit’ to textarea and then alerts it).
You should be using
valrather thanhtmlto get the value of the textarea:Also,
e.preventDefault;does nothing without parenthesis after it:e.preventDefault();and @Phrogz pointed out that javascript is case sensitive andPreventDefaultdoes not exist… UsepreventDefaultinstead.