Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

validate 3 fields

0 views
Skip to first unread message

jr

unread,
Jul 29, 2010, 12:50:28 AM7/29/10
to
Something is not working on the validation script. The bu is
required in a search form. Zonenm and zoneid are required together.
If someone searches on a bu and also a zoneid, then they must also
search on the zonenm and vice versa.So it is either all 3 or just the
bu. The bu validation always works. HOwever if I search on bu and
zoneid for example, I get a message asking for zonenm, but
alternatively, if I ask for the zoneid and bu, it should ask for the
zonenm. I tried it with the 3rd else if as an else instead of else if
but then I got a syntax error. thanks,
<script type="text/javascript">
function checkscript() {
var ele = document.forms[0].elements;
if (!ele.search_bu.value) {
alert('The Business Unit is a required field!');
return false;
} else if (ele.search_zoneid.value && !ele.search_zonenm.value) {
alert('Zone ID but no zone number');
return false;

} else if(ele.search_zonenm.value && !ele.search_zoneid.value) {
alert('Zone Number but no zone id');
return false;
}
return true;
}
</script>

David Mark

unread,
Jul 29, 2010, 1:00:29 AM7/29/10
to

Why use else's at all? Each conditional branch returns after all. ;)

SAM

unread,
Jul 29, 2010, 9:23:53 AM7/29/10
to
Le 7/29/10 6:50 AM, jr a écrit :

> Something is not working on the validation script. The bu is
> required in a search form. Zonenm and zoneid are required together.

aren't you too tired to always ask the same thing ?

can't you think by yourself ?

if ( bu.value ) {
if ( zoneid.value && !zonenum.value ) { blah 1 }
else
if ( !zoneid.value && zonenum.value ) { blah 2 }
}
else { blah 0 }

the "blah"s must return false


--
sm

Denis McMahon

unread,
Jul 29, 2010, 1:30:50 PM7/29/10
to
On 29/07/10 05:50, jr wrote:

> Something is not working on the validation script. ...

> but then I got a syntax error. thanks,

What was the error message, and what line in the script did it identify?

Rgds

Denis McMahon

jr

unread,
Jul 29, 2010, 3:17:33 PM7/29/10
to
On Jul 29, 10:30 am, Denis McMahon <denis.m.f.mcma...@googlemail.com>
wrote:

There wasn't an error message but the user could perform the search
incorrectly. It is an enforced business rule to search only on both.

jr

unread,
Jul 29, 2010, 3:18:31 PM7/29/10
to
On Jul 29, 10:30 am, Denis McMahon <denis.m.f.mcma...@googlemail.com>
wrote:

I believe I this one does work. I was testing on the wrong page or
something else. It is not elegant but it works.

jr

unread,
Jul 29, 2010, 3:21:14 PM7/29/10
to
On Jul 29, 6:23 am, SAM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:
I'm sorry I figured it out. Yours is better but the other one works.
I need to read a Javascript book. I have done hardly any javascript
and the format is slightly different than php.

SAM

unread,
Jul 29, 2010, 5:21:47 PM7/29/10
to
Le 7/29/10 9:21 PM, jr a écrit :

> On Jul 29, 6:23 am, SAM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
> wrote:
>> Le 7/29/10 6:50 AM, jr a écrit :
>>
>>> Something is not working on the validation script. The bu is
>>> required in a search form. Zonenm and zoneid are required together.
>>
>> can't you think by yourself ?
>>
>> if ( bu.value ) {
>> if ( zoneid.value && !zonenum.value ) { blah 1 }
>> else
>> if ( !zoneid.value && zonenum.value ) { blah 2 }
>> }
>> else { blah 0 }
>>
>> the "blah"s must return false
>>
> I'm sorry I figured it out. Yours is better but the other one works.
> I need to read a Javascript book. I have done hardly any javascript
> and the format is slightly different than php.

not so much ... not so much ... if / else are the same everywhere ;-)

--
sm

David Mark

unread,
Jul 29, 2010, 6:39:19 PM7/29/10
to
On Jul 29, 5:21 pm, SAM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>

Pretty much and you don't need an else if the previous conditional
clause exits the function. JSLint is good for spotting these issues.

SAM

unread,
Jul 30, 2010, 2:27:46 PM7/30/10
to
Le 7/30/10 12:39 AM, David Mark a écrit :

Absolutely !
(posted too quickly :-( )

--
sm

Captain Paralytic

unread,
Jul 30, 2010, 3:03:33 PM7/30/10
to
On Jul 29, 2:23 pm, SAM <stephanemoriaux.NoAd...@wanadoo.fr.invalid>
wrote:

> Le 7/29/10 6:50 AM, jr a écrit :
>
> > Something is not working on the  validation script.  The bu is
> > required in a search form.  Zonenm and zoneid are required together.
>
> aren't you too tired to always ask the same thing ?
>
> can't you think by yourself ?
Of course not, this is JRough!

Captain Paralytic

unread,
Jul 30, 2010, 3:04:47 PM7/30/10
to

You are assuming that the poster is an intelligent being. It is
however JRough, to whom intelligence is a foreign land.

David Mark

unread,
Jul 30, 2010, 4:31:35 PM7/30/10
to

You are assuming I know one "JR" (or "jr") from the next. That's why
people should use unique "handles" on Usenet, preferably their real
name.

0 new messages