I am hving the problem inside a function that is validating form fields.
It takes the form name as argument. I used your example, with some
modifications but it does not seem to work:
function validate(theForm){
....
if (theForm.FR) { // FR is the field name, which is a group of radio
buttons
if (!getRadioButtonChecked(theForm.FR)) {
alert("Please make a selection ....")
return false;
}
}
....
}
Then in the form:
<form name..... onSubmit="return validate(this)>
....
<?php
if (some condition)
<input name="FR" type="radio" value=""
....
?>
So, the function getRadioButtonChecked is not supposed to be called if FR is
not defined, but it does get called and it chokes if the field is not
defined.
Isn't there something like "isdefined" or "isset" function in javascript?
Thanks.
"Janwillem Borleffs" <jw@jwscripts.com> wrote in message
news:40***********************@news.wanadoo.nl...
Xerxes wrote: Hi,
how can I check if an input field in a form is defined? I create the
field dynamically, so it could or could not be in the form.
if (document.forms['formName'].elements['elementName']) {
// Element name is defined
}
Instead of formName and elementName you can also use indexes.
JW