Keep in mind the value property of a select is not supported on all
browsers. I usually consider a textbox/textarea empty if there are only
spaces (I usually trim the values anyway.
Also keep in mind that "title" and "target" are properties of the form.
To avoid mixing up formfields and properties, I always have the
formfield names in uppercase (JS is case sensitive).
Finally, you can set the focus on the field that has an error to help
your user fill in the form.

Pascal

<SCRIPT LANGUAGE="_javascript_" TYPE="text/_javascript_">
<!--
function Validate(f){
var blank_pattern = /^\s*$/i;
if(blank_pattern.test(f.TITLE.value)){
alert("Title is required");
f.TITLE.select();
f.TITLE.focus();
return false;
}
if(blank_pattern.test(f.STORY.value)){
alert("Story is required");
f.STORY.select();
f.STORY.focus();
return false;
}
var selectedVal =
(f.TARGET.options[f.TARGET.selectedIndex].value!="");
if(blank_pattern.test(f.LINK.value)&&selectedVal){
alert("You must provide a link if you select a target");
f.LINK.select();
f.LINK.focus();
return false;
}
if(!blank_pattern.test(f.LINK.value)&&!selectedVal){
alert("You must select a target if you provide a link");
f.TARGET.focus();
return false;
}
return true;
}
//-->
</SCRIPT>
<form ... Validate(this)">

> -----Original Message-----
> From: Asim Manzur [mailto:[EMAIL PROTECTED]
> Sent: maandag 28 juni 2004 22:47
> To: CF-Talk
> Subject: Re: _javascript_ help
>
> Thanks Mike,
>
> That works great.
>
> What if the user change the value of the target from "" to
> "_self" or "_blank" then I need to display the msg to put the
> Link as well.
>
> thanks
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to