if statement

Discussion in 'ASP General' started by Roy, Jun 2, 2004.

  1. Roy

    Roy Guest

    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!!?

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Roy, Jun 2, 2004
    #1
    1. Advertising

  2. Roy

    Keon Guest

    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 > " " ) {// 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!!?
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Keon, Jun 2, 2004
    #2
    1. Advertising

  3. Roy

    Roy Guest

    Roy, Jun 2, 2004
    #3
  4. > 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.)
    Aaron [SQL Server MVP], Jun 2, 2004
    #4
  5. Roy

    Keon Guest

    "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
    Keon, Jun 3, 2004
    #5
  6. Roy

    Evertjan. Guest

    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)
    Evertjan., Jun 3, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    790
  2. Jay McGavren
    Replies:
    11
    Views:
    1,113
    Alan Krueger
    Jan 16, 2006
  3. tedsuzman
    Replies:
    2
    Views:
    7,064
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  4. Ted
    Replies:
    1
    Views:
    451
    Duncan Booth
    Jul 22, 2004
  5. Replies:
    21
    Views:
    1,038
    Giannis Papadopoulos
    Aug 2, 2005
Loading...

Share This Page