There's a field in a form where a submit button is disabled by default. If that field is empty, the submit button is to remain disabled. Which if not empty, the submit button is to enable. When the field is cleared, the button is to be disabled again.
I unsuccessfully tried various ways to access the element and check if it's empty or not but the submit button remains enabled even if field is cleared after adding characters on it. Interestingly enough,the if(document.getElementById('Internal__c_dummy').value != '') is not false even if the field is cleared.
Could you please point me out to what I am missing here?
Thanks a lot!!
<g:hiddenField name="Internal__c" value="${Instance?.Internal__c}"/>
<g:textField class="internal-text" name="Internal__c_dummy" onchange="this.form.elements['Internal__c'].value = this.value" onkeyup="checkInternalText();" maxlength="20" />
<script type="text/Javascript">
function checkInternalText()
{
var empty = false; //Specifies if required fields are populated
var submitElement = document.getElementById('Submit')
if(document.getElementById('Internal__c_dummy').value != '')
{
alert('not empty')
submitElement.removeAttribute('disabled');
}
else{
alert('empty')
submitElement.setAttribute('disabled','true');
}
}
</script>
//Button
<g:submitButton name="Submit" class="Submit" value="Submit" disabled="true"/>