473,772 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The code inside the else block is not getting executed.

Hiii,
Please read the following piece of code:-
function SendToWebServer 1(sendto) //sendto string contains a URL
{

if (document.form1 .txtbookedby.va lue == "")
{
alert('your name field cannot be empty');
}
else if (document.form1 .txtContact.val ue == "")
{
alert('The extension number field cannot be empty');
}
/* else if (document.form1 .txtContact.val ue != "") //To chk user has
added only digits
{
for (var i = 0; i <
document.form1. txtContact.valu e.length;i++){
var ch=document.for m1.txtContact.v alue.charAt(i);
alert (i);
if((ch < "0" || ch "9")){
alert('the extension field can only have numbers');
}
}
alert("successf ully come out of loop");
}*/
else
{
alert("hey youve filled alll the fields correct ");
document.form1. action=sendto;
document.form1. submit();
}
}
Now the problem is with the part of code I have commented .

Problem:-
When I remove the coments ,it properly checks the first three
conditions and gives respective alert boxes when the conditions are
true.But when all the 3 conditions are false (that is conditions given
in the if ,1st elseif and 2nd elseif ) it doesnot go inside the Else
block.

Now when I add coments to the 2nd else if block ,it works fine .When
the if and the first elseif are false,it goes into the else block
displays the alert box and also performs these actions.
document.form1. action=sendto;
document.form1. submit();
as needed and takes me to the URL given in "sendto".

But when I remove the coments and all the fields are properly filled
it doesnot direct me to the string"sendto" page.

Please let me know where is the problem in the code.

Regards
Divya

Sep 20 '06 #1
3 1533
Yep I got my mistake. Because the second Elseif condition is satisfied
it enters inside executes the block and hence else is not executed.

divya wrote:
Hiii,
Please read the following piece of code:-
function SendToWebServer 1(sendto) //sendto string contains a URL
{

if (document.form1 .txtbookedby.va lue == "")
{
alert('your name field cannot be empty');
}
else if (document.form1 .txtContact.val ue == "")
{
alert('The extension number field cannot be empty');
}
/* else if (document.form1 .txtContact.val ue != "") //To chk user has
added only digits
{
for (var i = 0; i <
document.form1. txtContact.valu e.length;i++){
var ch=document.for m1.txtContact.v alue.charAt(i);
alert (i);
if((ch < "0" || ch "9")){
alert('the extension field can only have numbers');
}
}
alert("successf ully come out of loop");
}*/
else
{
alert("hey youve filled alll the fields correct ");
document.form1. action=sendto;
document.form1. submit();
}
}
Now the problem is with the part of code I have commented .

Problem:-
When I remove the coments ,it properly checks the first three
conditions and gives respective alert boxes when the conditions are
true.But when all the 3 conditions are false (that is conditions given
in the if ,1st elseif and 2nd elseif ) it doesnot go inside the Else
block.

Now when I add coments to the 2nd else if block ,it works fine .When
the if and the first elseif are false,it goes into the else block
displays the alert box and also performs these actions.
document.form1. action=sendto;
document.form1. submit();
as needed and takes me to the URL given in "sendto".

But when I remove the coments and all the fields are properly filled
it doesnot direct me to the string"sendto" page.

Please let me know where is the problem in the code.

Regards
Divya
Sep 20 '06 #2

divya wrote:
if (document.form1 .txtbookedby.va lue == "")
{
alert('your name field cannot be empty');
}
else if (document.form1 .txtContact.val ue == "")
{
alert('The extension number field cannot be empty');
}
else if (document.form1 .txtContact.val ue != "")
{
[...]
}
else
{
alert("hey youve filled alll the fields correct ");
[...]
}
When I remove the coments ,it properly checks the first
three conditions and gives respective alert boxes when
the conditions are true.But when all the 3 conditions are
false (that is conditions given in the if ,1st elseif and
2nd elseif )...
You're mistaken. 'A or not A' can't *ever* be false (if you
stick to binary logic, of course). The condition in the
second else if is a negation of a condition in the first
else if. They can't both be false at the same time.

--
Pavel Lepin

Sep 20 '06 #3
Yes thats what clicked me after posting that at a time one of the
first elseif or second elseif has to be true and in either cases Else
will never be executed.Aneway z thanks for replying.
p.*****@ctncorp .com wrote:
divya wrote:
if (document.form1 .txtbookedby.va lue == "")
{
alert('your name field cannot be empty');
}
else if (document.form1 .txtContact.val ue == "")
{
alert('The extension number field cannot be empty');
}
else if (document.form1 .txtContact.val ue != "")
{

[...]
}
else
{
alert("hey youve filled alll the fields correct ");

[...]
}
When I remove the coments ,it properly checks the first
three conditions and gives respective alert boxes when
the conditions are true.But when all the 3 conditions are
false (that is conditions given in the if ,1st elseif and
2nd elseif )...

You're mistaken. 'A or not A' can't *ever* be false (if you
stick to binary logic, of course). The condition in the
second else if is a negation of a condition in the first
else if. They can't both be false at the same time.

--
Pavel Lepin
Sep 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
5937
by: Hung Jung Lu | last post by:
Hi, I know people have talked about it before, but I am still really confused from reading the old messages. When I talk about code blocks, I am not talking about Lisp/Ruby/Perl, so I am not making comparisons. If you have a file, in Python you could do:
38
3542
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser = serial.Serial()
27
3079
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a few weeks ago while trying to find the best way to form a if-elif-else block, that on a very general level, an 'also' statement might be useful. So I was wondering what others would think of it.
16
3113
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
18
3163
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My question is what happens to the dynamically created assembly when the method is done running? Does GC take care of it? Or is it stuck in RAM until the ASP.Net process is recycled? This code executes pretty frequently (maybe 4 times per transaction) and...
5
2699
by: portroe | last post by:
Hi, how can I get my forms program to perform a particular action again if the incorrect format is entered, I have tried GOTO line xxx
232
13343
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first set of examples, after decoding the HTML FORM contents, merely verifies the text within a field to make sure it is a valid representation of an integer, without any junk thrown in, i.e. it must satisfy the regular expression: ^ *?+ *$ If the...
12
1243
by: why? | last post by:
I've been having problem with the following code. It's supposed to print the prime numbers between 10 and 100. But i'm not getting any output, i.e. i guess the outer 'for' loop is being traversed only once. I would be greatful if you could help me out. Thanx! .... for j in range(2,i): .... if i%j==0: .... f=0 .... break .... else: continue .... if f==1:
7
1542
by: Ixiaus | last post by:
I have just come across a site that discusses Python's 'for' and 'while' loops as having an (optional) 'else' structure. At first glance I interpreted it as being a bit like the 'default' structure in PHP's switch block... But the switch block isn't a loop, so, I am now confused as to the reason for using 'else' with the for and while loops... A few quick tests basically show that statements in the else structure are executed at the...
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.