Mike,
I've got everything working, except sometimes the child control may not be
an input box. Here is the JS validation after it has been served:
**********************
<script type="text/javascript">
function checkForm(form)
{
var c = form.elements, e, t;
for( var i = 0, n = c.length; i < n; ++i )
{
t = ( e = c[ i ]).type;
if(( 'select-one' == t ) && ( e.selectedIndex == 0 ) &&
isRequired( e ))
{
alert("Please select an option for " + e.title + ".");
form.validated.value="false";
return false;
}
else if(( 'text' == t ) && ( e.value.length < 1 ) && isRequired( e ))
{
alert("Please enter a value for " + e.title + ".");
form.validated.value="false";
return false;
}
else if(( 'textarea' == t ) && ( e.value.length < 1 ) && isRequired( e ))
{
alert("Please enter a value for " + e.title + ".");
form.validated.value="false";
return false;
}
// etc.
else if((e.id=='DomeLight')&&(e.selectedIndex>=2)){
var cValue = form.elements['DomeLightFB'].value;
if(isNaN(cValue)||(cValue<1)){
alert('Please enter a value for Dome Light Location.');
form.validated.value='false';
return false;}}
}
form.validated.value="true";
return true;
}
function isRequired( e )
{
return( -1 != e.className.indexOf( 'required' ));
}
function setVisibility( ref, visible ) {
if( ref && ref.style ) {
ref.style.visibility = visible ? '' : 'hidden';
}
}
function enableChild( r,child,trigger ) {
var f = r.form, i = r.selectedIndex, childControl = f.elements[ child ];
setVisibility( childControl, i >= trigger);
/* disable the control in case the browser doesn't support
the inline style object */
childControl.disabled = ( i < trigger);
}
//-->
</script>
**********************
The lines in question are:
else if((e.id=='DomeLight')&&(e.selectedIndex>=2)){
var cValue = form.elements['DomeLightFB'].value;
if(isNaN(cValue)||(cValue<1)){
alert('Please enter a value for Dome Light Location.');
form.validated.value='false';
return false;}}
'DomeLight' is a select that has a child select called 'DomeLightFB' when
the selected index is >=2.
If 'DomeLightFB' is an input control, this works fine. But as a selectbox,
it doesn't. I need to check if the value is < 1 (for children that are input
controls), and selectedIndex ==0 (for children that are selects).
I tried adding an OR to the value test line, but it doesn't want to work for
some reason:
if( isNaN(cValue)||(cValue<1) || (form.elements['DomeLightFB'].selectedIndex
== 0)){
Any ideas?
Thanks once again for all the invaluable help!
Calan
"Calan" <no**@nospam.com> wrote in message
news:10*************@corp.supernews.com...
Thanks Mike... this is soaking in (slowly), but I'm still not seeing a
way to make it work for ANY control that is somehow designated as a "child" of
another control.
I'm thinking I can add an ASP variable called 'ControlParent" (which comes
from the database of control definitions). This variable will contain the
name of the control that it is dependent on, if there is one. But I also
need to set the parent's index that will trigger the visibility.
I'm working through your example below for a known control (Length), but
still not quite grasping how to make it work for any control, as defined
in the ASP script.
(Maybe dynamically create the JS with response.write, inserting control
names where appropriate? Would this be easier than a generic JS function
that can handle any control that has some property that identifies it as
having a dependency?)
Once again thanks for your help...
Calan
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk... On Thu, 08 Apr 2004 14:57:58 GMT, Michael Winter
<M.******@blueyonder.co.invalid> wrote:
[snip]
<form ...>
<select name="length" onchange="enableLength(this)">
<!-- options -->
</select>
<input name="vLength" type="text">
</form>
[snip]
Forgot to mention that after the closing form tag, you should call
enableLength():
<script type="text/javascript>
enableLength( document.forms[ 'formName' ].elements[ 'length' ]);
</script>
Mike
--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)