473,785 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

if statement syntax?

Hello everyone
I'm doing a multiple insert from ten text fields.
all named color
when I submit the from with the text fields
it goes to an asp page with the script to do the job
and the go to another page, I've got that bit going but what if the user
leaves the fields empty an hits submit?
ok a simple enough thing of putting an else in the script, this isn't
working!! it always does the first thing
I've tried so many different variations.
it seems so simple but i just can't get it
here's the full script

<%@LANGUAGE="JA VASCRIPT" CODEPAGE="1252" %>

<%

var ProductID =1;
var colorForm = String(Request. QueryString("co lor"));//get the form
field and put into var
if(colorForm != "undefined" || colorForm != " " ){

var text = "" ;
colorForm = colorForm.repla ce(/'/g, "''");
colorForm_array = colorForm.split (",");//split at ","
for( i=0 ; i < colorForm_array .length ; i ++){// loop through the array
if (colorForm_arra y[i] > " " ) {// if there is something in the array

conn = Server.CreateOb ject('ADODB.Com mand');//make the sql connection
object and open it here
conn.ActiveConn ection = "dsn=Blenz; ";
conn.CommandTex t = ("insert into color (color,ProductI D) values ('" +
colorForm_array[i] + "','" + ProductID + "')" ) //insert into table
field/s
conn.Execute();//do the job
conn.ActiveConn ection.Close();//close

}
}
Response.Redire ct("coloursOn.a sp?ProductID=" +ProductID) ;
}

else
{
Response.Redire ct("insert_done .asp?ProductID= " +ProductID)
}
Jul 23 '05 #1
3 1895
Roy Adams wrote:
<snip>
if(colorForm != "undefined" || colorForm != " " ){

<snip>

You logic is addressing three possibilities: 1. The - colorForm - string
is "undefined" , 2. the string is a space character, or 3. the string is
something else.

In reverse order: 3. If the string is something else then the -
colorForm != "undefined" - expression evaluates as true and the body of
the if statement is executed.

2. If the string is a space character - colorForm != "undefined" - also
evaluates as true and the body of the if statement is executed.

1. If the string is "undefined" then - colorForm != "undefined" -
evaluates as false, _but_ you have used a logical OR operator (||) so
the right hand side of that operation is evaluated because the left hand
side is false. So if the string is "undefined" then - colorForm != "
" - is evaluated and that expression returns true, the body of the if
statement is executed.

You don't see the - else - branch being executed because the if
statement is true for all input. You should be using a logical AND
operator (&&) between the two expressions (and learning something about
programming before attempting it as boolean logic is completely
fundamental to the practice).

Richard.
Jul 23 '05 #2
Lee
Roy Adams said:

Hello everyone
I'm doing a multiple insert from ten text fields.
all named color
when I submit the from with the text fields
it goes to an asp page with the script to do the job
and the go to another page, I've got that bit going but what if the user
leaves the fields empty an hits submit?
ok a simple enough thing of putting an else in the script, this isn't
working!! it always does the first thing
I've tried so many different variations.
it seems so simple but i just can't get it
here's the full script if(colorForm != "undefined" || colorForm != " " ){


That reads: if colorForm is not "undefined" or colorForm is not " ".

Unless colorForm is both "undefined" and " " at the same time,
that expression will always be true.

You probably meant "&&" instead of "||".

Note that your second test is testing to see if the value is a single
space, which is not the same as testing to see if it's empty. That
would be "", with no space in between.

Jul 23 '05 #3
Roy
Thanks for your help
Richard but all that's happening now is that all thats being executed is
the else part of the script
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4

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

Similar topics

47
3650
by: Andrey Tatarinov | last post by:
Hi. It would be great to be able to reverse usage/definition parts in haskell-way with "where" keyword. Since Python 3 would miss lambda, that would be extremly useful for creating readable sources. Usage could be something like: >>> res = where: >>> def f(x):
6
19172
by: HeadScratcher | last post by:
I am trying to speed up my update statements by removing inner select statements. Example: update orders set shipname = (select contactName from customers where customerid = orders.customerID) I read some articles which said that I should be able to use an inner join on the update statement like the following:
7
6672
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks!
13
2575
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){}, my_meth2: function(){} }); to define new methods on the MyObj prototype object. Object.extend
37
3312
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html PEP: XXX Title: The create statement
18
2723
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt http://ucsu.colorado.edu/~bethard/py/pep_create_statement.html In this post, I'm especially soliciting review of Carl Banks's point (now discussed under Open Issues) which asks if it would be better to have the create statement translated into:
28
2952
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions! PEP: 359 Title: The "make" Statement Version: $Revision: 45366 $ Last-Modified: $Date: 2006-04-13 07:36:24 -0600 (Thu, 13 Apr 2006) $
7
2702
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about the goals -- the make statement is mostly syntactic sugar for:: class <name> <tuple>: __metaclass__ = <callable>
6
2172
by: Heiko Wundram | last post by:
Hi all! The following PEP tries to make the case for a slight unification of for statement and list comprehension syntax. Comments appreciated, including on the sample implementation. === PEP: xxx Title: Unification of for-statement and list-comprehension syntax
23
2076
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return Result(1) 3. Evaluate SourceElement. 4. Return Result(3). If I understood correctly the following program should alert 'undefined': alert(eval('3;;'));
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9958
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
8986
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...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
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
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
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
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.