Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-21-2003, 11:11 PM   PM User | #1
Crash1hd
Regular Coder

 
Join Date: Jul 2002
Location: 51° 03' -78" N -114° 05' 72" W
Posts: 617
Thanks: 0
Thanked 0 Times in 0 Posts
Crash1hd is an unknown quantity at this point
useing javascript check to check document

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

Quote:
{
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
Crash1hd is offline   Reply With Quote
Old 01-22-2003, 03:46 AM   PM User | #2
ez4ne12c
Regular Coder

 
Join Date: Jun 2002
Location: Australia
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
ez4ne12c is an unknown quantity at this point
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
__________________
Animation Rule #64
Poor quality images are often artistic,
Poor quality sound is ALWAYS annoying.
ez4ne12c is offline   Reply With Quote
Old 01-22-2003, 04:57 AM   PM User | #3
Crash1hd
Regular Coder

 
Join Date: Jul 2002
Location: 51° 03' -78" N -114° 05' 72" W
Posts: 617
Thanks: 0
Thanked 0 Times in 0 Posts
Crash1hd is an unknown quantity at this point
Actually I was able to figure it out all I had to do was tell it this

Quote:
{
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!
Crash1hd is offline   Reply With Quote
Old 01-22-2003, 09:07 PM   PM User | #4
ez4ne12c
Regular Coder

 
Join Date: Jun 2002
Location: Australia
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
ez4ne12c is an unknown quantity at this point
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
__________________
Animation Rule #64
Poor quality images are often artistic,
Poor quality sound is ALWAYS annoying.
ez4ne12c is offline   Reply With Quote
Old 01-23-2003, 12:10 AM   PM User | #5
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
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:

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.
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)

Last edited by whammy; 01-23-2003 at 12:25 AM..
whammy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:52 AM.


Advertisement
Log in to turn off these ads.