I want to make submit event depend textarea value. cause i want to check textarea is vaild. so when I was using javascript function getElementByid, it result was placeholder value.
I just want to know how can I fix it.
<div class="clearfix">
<div class="input">
<textarea name="comment" id="comment" placeholder="<?php _e("Your Comment Here", "bonestheme"); ?>" tabindex="4" style="border:1px solid #cbcbcb; resize:none"></textarea>
</div>
</div>
<div class="form-actions">
<input class="btn-commnet" name="submit" type="submit" id="submit" tabindex="5" value="<?php _e("Submit Comment","bonestheme"); ?>" />
</div>
<?php endif; ?>
You can use .value. Here's a demo:
var textarea = document.getElementById('test');
var result = document.getElementById('result');
function updateResult() {
result.textContent = textarea.value;
}
textarea.addEventListener('keyup', updateResult);
<textarea id="test" placeholder="Some placeholder"></textarea>
<p id="result"></p>
A little unclear as to what you need to do but if you just want to validate that the textarea value is something other then the placeholder text, you could add a handler to call on click of the button, something like:
<input class="btn-commnet" name="submit" type="submit" id="submit" tabindex="5" value="<?php _e("Submit Comment","bonestheme"); ?>" onclick="return ValidationEvent()"/>
then have a javascript function that checks the value prior to submitting..
function ValidationEvent() {
commentElm = document.getElementById('comment');
if(commentElm.value === commentElm.placeholder)
return false;
return true;
}
This could be greatly simplified using Jquery.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With