Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > if statement

Reply
Thread Tools

if statement

 
 
Roy
Guest
Posts: n/a
 
      06-02-2004
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[i] > " " ) {// 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[i] + "','" + 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!!?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Keon
Guest
Posts: n/a
 
      06-02-2004
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

"Roy" <me@no_spam.com> wrote in message
news:...
> 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[i] > " " ) {// 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[i] + "','" + 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!!?
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
 
 
 
Roy
Guest
Posts: n/a
 
      06-02-2004
is that javascript?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Aaron [SQL Server MVP]
Guest
Posts: n/a
 
      06-02-2004
> 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

--
http://www.aspfaq.com/
(Reverse address to reply.)


 
Reply With Quote
 
Keon
Guest
Posts: n/a
 
      06-03-2004

"Roy" <me@no_spam.com> wrote in message
news:...
> is that javascript?
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!


No, it's ASP


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      06-03-2004
Keon wrote on 03 jun 2004 in microsoft.public.inetserver.asp.general:
> "Roy" <me@no_spam.com> wrote in message
> news:...
>> is that javascript?

>
> 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)



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if statement that, when false, skips first statement in its block, executes second? Jay McGavren Java 11 01-16-2006 05:49 PM
How do I do a conditional statement in a constant statement? tkvhdl@gmail.com VHDL 3 12-16-2005 06:13 PM
Which of switch statement and if-else statement takes less time to execute? swaroophr@gmail.com C Programming 21 08-02-2005 09:24 AM
exec "statement" VS. exec "statement in globals(), locals() Ted Python 1 07-22-2004 08:51 AM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM



Advertisments