This commit is contained in:
parent
8cb3756bbc
commit
42fa7eb4c1
|
@ -1,39 +1,3 @@
|
|||
<script>
|
||||
var W3CDOM = document.createElement && document.getElementsByTagName;
|
||||
|
||||
window.onload = setMaxLength;
|
||||
|
||||
function setMaxLength() {
|
||||
if (!W3CDOM) return;
|
||||
var textareas = document.getElementsByTagName('textarea');
|
||||
var counter = document.createElement('div');
|
||||
counter.className = 'counter';
|
||||
for (var i=0;i<textareas.length;i++) {
|
||||
if (textareas[i].getAttribute('maxlength')) {
|
||||
var counterClone = counter.cloneNode(true);
|
||||
counterClone.innerHTML = '<span>0</span>/'+textareas[i].getAttribute('maxlength');
|
||||
textareas[i].parentNode.insertBefore(counterClone,textareas[i].nextSibling);
|
||||
textareas[i].relatedElement = counterClone.getElementsByTagName('span')[0];
|
||||
textareas[i].onkeyup = textareas[i].onchange = checkMaxLength;
|
||||
textareas[i].onkeyup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkMaxLength() {
|
||||
var maxLength = this.getAttribute('maxlength');
|
||||
var currentLength = this.value.length;
|
||||
alert(currentLength);
|
||||
if (currentLength >= maxLength) {
|
||||
this.relatedElement.className = 'toomuch';
|
||||
}
|
||||
else {
|
||||
this.relatedElement.className = '';
|
||||
}
|
||||
this.relatedElement.firstChild.nodeValue = currentLength;
|
||||
}
|
||||
|
||||
</script>
|
||||
<%= form_tag({:controller => 'projects', :action => 'project_respond'}) do %>
|
||||
<%= text_area_tag 'project_respond', "",
|
||||
:class => 'noline', :required => true,
|
||||
|
|
Loading…
Reference in New Issue