- Add an id to your checkbox:
<input name='oth'
id='oth'
- Add an id to your textbox:
<input type='text' name='other'
id='other'
- Use this to checked whether the 'other' textbox is selected:
document.getElementById('oth').checked
- Slight change to aso's suggestion, which will work on if textfield.value is empty or null
(textfield.value || '').length <= 0
- Another change to aso's suggestion: checked AND empty (not OR)
- Then you end up with this:
- Code: Select all
if(document.getElementById('oth').checked && (document.getElementById('other').value || '').length <= 0) {
return false;
}
You should be able to make this work now...