php - Radio button text area -
i have survey form works fine. need 1 question changed. there's 2 radio buttons answers "yes" , "no" , text area under them. want text area locked unless user selects "yes" radio button can type in text area reason "yes".
i did looking around , attempting function doesn't seem working.
<script> function validate() { var radioyes = document.getelementbyid('radioyes'); var textarea = document.getelementbyid('question5comment'); if (radioyes.checked && question5comment.value.length < 1) { alert('please enter reason question 5.'); question5comment.focus(); return false; } } function toggle(value) { document.getelementbyid('question5comment').disabled = value; } </script> 5. using other non-franchise service centres? <br> *if yes there other reason other price <br> <input type="radio" name="question5" value="yes" required>yes <br> <input type="radio" name="question5" <value="no" required>no <br> <textarea name="question5comment" rows="5" cols="40" required></textarea>
your syntax wrong:
- unnecessary
<
beforevalue
. - no
id
s referring in code. - syntax errors.
use following:
function validate() { var radioyes = document.getelementbyid('radioyes'); var textarea = document.getelementbyid('question5comment'); if (radioyes.checked && question5comment.value.length < 1) { alert('please enter reason question 5.'); question5comment.focus(); document.getelementbyid('question5comment').disabled = true; return false; } else { document.getelementbyid('question5comment').disabled = false; } }
5. using other non-franchise service centres? <br>*if yes there other reason other price <br> <input type="radio" name="question5" value="yes" required onclick="validate();" id="radioyes" />yes <br> <input type="radio" name="question5" value="no" required onclick="validate();" id="radiono" />no <br> <textarea name="question5comment" id="question5comment" rows="5" cols="40" required></textarea>
Comments
Post a Comment