By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,963 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,963 IT Pros & Developers. It's quick & easy.

Form Validation - check textbox filled in if radio button clicked

P: n/a
I have created a form at
http://www.habitatforhumanity.org.uk...ndiv_apply.htm

In the Medical Details section we need to ensure that if a radio
button is clicked to indicate a health issue then the textarea box is
filled in.

Is there a way to do this?

I am not an expert in Javascript so please treat me as stupid!

Thanks.
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Claire Osborne" <cl****@interface-web.co.uk> wrote in message
news:12**************************@posting.google.c om...
I have created a form at
http://www.habitatforhumanity.org.uk...ndiv_apply.htm

In the Medical Details section we need to ensure that if a radio
button is clicked to indicate a health issue then the textarea box is
filled in.

Is there a way to do this?

I am not an expert in Javascript so please treat me as stupid!

Thanks.

Here's a function that will identify which textareas are blank when there
corresponding radiobutton is "yes".

function radiotext() {
var form = document.application;
var errs = "";
for (i=0; i<form.elements.length; i++) {
if (form.elements[i].type == "radio") {
if (form.elements[i].value == "yes") {
if (form.elements[i].checked) {
if (form.elements[i+1].value == "") {
errs += "\n" + form.elements[i+1].name;
}
}
}
}
}
if (errs != "") {
alert("Please enter:\n" + errs);
return false;
}
return true;
}
It can be called by adding the following line to the "form" tag:

onsubmit="return radiotext()"
Jul 20 '05 #2

P: n/a
Absolutely brilliant - thank you!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

P: n/a
On 10 Feb 2004 17:49:49 GMT, Claire Osborne <cl****@interface-web.co.uk>
wrote:
Absolutely brilliant - thank you!


Though client-side validation is fine, don't forget to validate on the
server, too.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.