...

View Full Version : using javascript check to check document



Crash1hd
01-22-2003, 12:11 AM
I have 6 field boxes and i want if the first three are the same as the second three and then check box is marked that it brings up an alert but if the checkbox is marked and the second three are blank it continues I have the following


{
if(document.mailform.Night_Phone_Same_As_Day.checked == true)
{
if (document.mailform.night_phone_a.value == "" | document.mailform.night_phone_b.value == "" | document.mailform.night_phone_c.value == ""){return true;}
else if (document.mailform.night_phone_a.value != document.mailform.day_phone_a.value | document.mailform.night_phone_b.value != document.mailform.day_phone_b.value | document.mailform.night_phone_c.value != document.mailform.day_phone_c.value)
{
alert("Please Dont Check the box if Night phone is different then day!")
return
}
}}

Where the return true; is is what I dont know what to put to tell it to ignore the else if and continue :)

Thanks in advance

ez4ne12c
01-22-2003, 04:46 AM
I dont think your problem is difficult im just not sure what it is?

You have a check box to say night phone i same as day
to save the user entering the same data twice
there are 3 possible phone numbers a, b, c for day and 3 for night..

so if all the nights are blank and the user checks SAME checkbox
then return true

if all nights have been filled in and are same and user checks SAME checkbox
then return true

else if user checks SAME and a day != a night ,,b,,c then alert

is that it?
ez

Crash1hd
01-22-2003, 05:57 AM
Actually I was able to figure it out all I had to do was tell it this


{
if(document.mailform.Night_Phone_Same_As_Day.checked == true)
{
if (document.mailform.night_phone_a.value == "" | document.mailform.night_phone_b.value == "" | document.mailform.night_phone_c.value == "")
{
(document.mailform.night_phone_a.value == document.mailform.day_phone_a.value | document.mailform.night_phone_b.value == document.mailform.day_phone_b.value | document.mailform.night_phone_c.value == document.mailform.day_phone_c.value)
}
else if (document.mailform.night_phone_a.value != document.mailform.day_phone_a.value | document.mailform.night_phone_b.value != document.mailform.day_phone_b.value | document.mailform.night_phone_c.value != document.mailform.day_phone_c.value)
{
alert("Please Dont Check the box if Night phone is different then day!")
return
}}

that way when it was blank then the one is forwarded with the other! It makes sence but just hard to explain!

ez4ne12c
01-22-2003, 10:07 PM
You might like to add this line
....
....
{
document.mailform.Night_Phone_Same_As_Day.checked = false;
alert("Please Dont Check the box if Night phone is different then day!")
return
}....
...
ez

whammy
01-23-2003, 01:10 AM
I bet if you post your 3 form fields, and your function, I can shorten (or improve) it considerably, at least if you're only dealing with US and Canadian phone numbers...

Just a tip to shorten your script (wow, that sounds like Dr. Suess!):

If you're using something like document.mailform.
over and over again, set it to a variable, such as:

var f = document.mailform;

From that point on, you can say stuff like:

if (f.night_phone_a.value == "" | f.night_phone_b.value == "" | f.night_phone_c.value == "") {

instead of the really lengthy code you have.

Alternatively (and even better), you can just use (f) in the function parameter, and pass (this) from the form tag using onsubmit. What that does, is passes the form object to the function parameter "f" right when you're calling the function - that way the function always knows that "f" is the form that called the function... get it? If not, here's an example that might clarify what I mean, since sometimes I'm better at explaining with code:



<html>
<head>
<title>Example</title>
<script type="text/javascript">
<!--
function alertFormName(f) {
alert(f.name + f.punctuation.value);
return false;
}
// -->
</script>
</head>
<body>
<form name="Yay" action="javascript://" onsubmit="alertFormName(this)">
<input type="hidden" name="punctuation" value="!!!" />
<input type="submit" value="Submit" />
</form>
</body>
</html>


Also, I'd rather allow people to type a phone number all in one field, and then validate the phone number against a regular expression, rather than having to deal with three separate fields for each phone number. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum