if statement

R

Roy

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="JAVASCRIPT" CODEPAGE="1252"%>

<%

var ProductID =1;
var colorForm = String(Request.QueryString("color"));//get the form
field and put into var


if(colorForm != "undefined" || colorForm != " " ){

var text = "" ;
colorForm = colorForm.replace(/'/g, "''");
colorForm_array = colorForm.split(",");//split at ","


for( i=0 ; i < colorForm_array.length ; i ++){// loop through the array
if (colorForm_array > " " ) {// if there is something in the array

conn = Server.CreateObject('ADODB.Command');//make the sql connection
object and open it here
conn.ActiveConnection = "dsn=Blenz;";
conn.CommandText = ("insert into color (color,ProductID) values ('" +
colorForm_array + "','" + ProductID + "')" ) //insert into table
field/s
conn.Execute();//do the job
conn.ActiveConnection.Close();//close

}
}
Response.Redirect("coloursOn.asp?ProductID=" +ProductID) ;
}

else
{
Response.Redirect("insert_done.asp?ProductID=" +ProductID)


}


%>

what's wrong with this!!?
 
K

Keon

Use in your if line a strcmp

For excample

If strcmp(color,"")=0 then

error message because text field is empty

Else

text field isn't empty

End if

Greets

Keon
 
A

Aaron [SQL Server MVP]

and the go to another page, I've got that bit going but what if the user
leaves the fields empty an hits submit?

Well, that depends. Is it acceptable for the user to select 0 colors? If
not, then use client-side validation to say "hey, select a color" instead of
submitting the form when they click submit.

Otherwise, I believe you can check Request.QueryString("color").length
 
E

Evertjan.

Keon wrote on 03 jun 2004 in microsoft.public.inetserver.asp.general:
No, it's ASP

Wrong:

ASP is a platform for serverside jscript or vbscript or whatever.

If the [not quoted] subject was:
If strcmp(color,"")=0 then

Than the answer is [under ASP if On Topic in this NG]:

No, it is vbscript.


J(ava)script, also under ASP, has no "then" and has a double "==" for equal
comparison, so that would look likwe this:

If (strcmp(color,"")==0)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top