Reputation: 3978
Today I came across a weird situation where an element registered using jQuery keyup (or any event for that matter) would undefine that element from the FORM scope upon submitting my form. I am using jQuery 1.4.4 version and a jQuery plugin named highlightTextarea. Has anyone faced this situation or is it just a novice mistake?
I did scour the internet for fixes, like library overriding, jQuery overriding and other conflicts. I tried changing my layout, selectors etc but did not have any luck. The moment I remove this event registration, everything works normal. I tried with different events and the result was same.
My jQuery code inside the document ready function:
$('#settlement_details').keyup(function (e) {
updateCount($(this)); // updates the character count inside my textarea to a div
});
My HTML:
<table>
<tr>
<td colspan="4" class="formfield"><span class="formlabel">Settlement Details (Max 600 characters)</span><br>
<textarea cols="60" data-maxlength="600" rows="5" id="settlement_details" name="settlement_details">#settlement_details#
</textarea><br>
Character Count:<span id="charNum"></span>
</td>
</tr>
</table>
Upvotes: 0
Views: 53
Reputation: 3978
The solution i had to come up with was to have a hidden variable to copy the data to and have the submit and validations to work. I am not sure this is the perfect solution but the only one I could devise to. My edited code was:
$('#settlement_details').keyup(function (e) {
updateCount($(this));
$('input[name=settlement_details]').val($('#settlement_details').val());
});
HTML:
<input type="hidden" name="settlement_details" value="">
Upvotes: 1