If / Then / Else Help Needed - More then one condition possible?

Discussion in 'Javascript' started by tbird2340@gmail.com, Sep 19, 2006.

  1. Guest

    I want to write an if / then statement and have tried using this:

    var MyVarMailto;
    if (Request.Form("LoanRequest") == "Under $250,000") {
    if (Request.Form("Organization") == "1") {
    MyVarMailto = "";
    }
    }
    else if (Request.Form("LoanRequest") == "Over $250,000") {
    if (Request.Form("Organization") == "1") {
    MyVarMailto = "";
    }
    }
    else {
    MyVarMailto = "";
    }

    So basically I have a form that gets filled out and submitted which
    passes the values to this page. I want to check the values against
    conditions that you can probably figure out above and then set the
    variable contigent to those values. I tried using AND after the first
    condition but that doesn't do anything. Please help. Thanks so much.
     
    , Sep 19, 2006
    #1
    1. Advertising

  2. VK Guest

    wrote:
    > var MyVarMailto;
    > if (Request.Form("LoanRequest") == "Under $250,000") {
    > if (Request.Form("Organization") == "1") {
    > MyVarMailto = "";
    > }
    > }
    > else if (Request.Form("LoanRequest") == "Over $250,000") {
    > if (Request.Form("Organization") == "1") {
    > MyVarMailto = "";
    > }
    > }
    > else {
    > MyVarMailto = "";
    > }


    what object is Request? what object is Form? what object is LoanRequest
    (select list, textbox, radiogroup)?
     
    VK, Sep 19, 2006
    #2
    1. Advertising

  3. VK Guest

    wrote:
    > var MyVarMailto;
    > if (Request.Form("LoanRequest") == "Under $250,000") {
    > if (Request.Form("Organization") == "1") {
    > MyVarMailto = "";
    > }
    > }
    > else if (Request.Form("LoanRequest") == "Over $250,000") {
    > if (Request.Form("Organization") == "1") {
    > MyVarMailto = "";
    > }
    > }
    > else {
    > MyVarMailto = "";
    > }


    what object is Request? what object is Form? what object is LoanRequest
    (select list, textbox, radiogroup)?
     
    VK, Sep 19, 2006
    #3
  4. wrote:
    > if (Request.Form("LoanRequest") == "Under $250,000") {
    > if (Request.Form("Organization") == "1") {
    > MyVarMailto = "";
    > }
    > }
    >[...] . I tried using AND after the first
    > condition but that doesn't do anything. Please help. Thanks so much.


    if ((Request.Form("LoanRequest") == "Under $250,000") &&
    (Request.Form("Organization") == "1") )
    MyVarMailto = "";
    else
    if ...

    && = AND, || = OR

    Kev
     
    Kevin Darling, Sep 19, 2006
    #4
  5. McKirahan Guest

    <> wrote in message
    news:...
    > I want to write an if / then statement and have tried using this:
    >
    > var MyVarMailto;
    > if (Request.Form("LoanRequest") == "Under $250,000") {
    > if (Request.Form("Organization") == "1") {
    > MyVarMailto = "";
    > }
    > }
    > else if (Request.Form("LoanRequest") == "Over $250,000") {
    > if (Request.Form("Organization") == "1") {
    > MyVarMailto = "";
    > }
    > }
    > else {
    > MyVarMailto = "";
    > }
    >
    > So basically I have a form that gets filled out and submitted which
    > passes the values to this page. I want to check the values against
    > conditions that you can probably figure out above and then set the
    > variable contigent to those values. I tried using AND after the first
    > condition but that doesn't do anything. Please help. Thanks so much.


    JScript and ASP, eh? Perhaps this is what you want:

    var MyVarMailto = ;
    var MyAmt = "<%=Request.Form("LoanRequest")%>";
    var MyOrg = "<%=Request.Form("Organization")%>";

    if (MyOrg == "1") {
    if (MyAmt == "Under $250,000") {
    MyVarMailto = "";
    } else if (MyAmt == "Over $250,000") {
    MyVarMailto = "";
    }
    }
     
    McKirahan, Sep 19, 2006
    #5
  6. Guest

    Yes, Jscript and ASP.. I know. I don't like it either but it's the only
    site I setup like this the rest are VB and asp..

    I tried a couple of the suggestions. It seems like for whatever reason
    the variable isn't getting set.

    I tried using this:

    var MyVarMailto;
    if ((Request.Form("LoanRequest") == "Under $250,000") &&
    (Request.Form("Organization") == "1")) {
    MyVarMailto = "";
    }
    else if ((Request.Form("LoanRequest") == "Over $250,000") &&
    (Request.Form("Organization") == "1")) {
    MyVarMailto = "";
    }
    else {
    MyVarMailto = "";

    And also this:

    var MyVarMailto = "";
    var MyAmt = Request.Form("LoanRequest");
    var MyOrg = Request.Form("Organization");

    if (MyOrg == "1") {
    if (MyAmt == "1") {
    MyVarMailto = "";
    } else if (MyAmt == "2") {
    MyVarMailto = "";
    }
    }

    I shouldn't say the variable isn't getting set.. It's acting like none
    of the conditions are matching and it's using the "ELSE" email
    address.. The values are getting passed and that's why I'm confused.
    Any ideas? Thanks!
     
    , Sep 20, 2006
    #6
  7. McKirahan Guest

    <> wrote in message
    news:...
    > Yes, Jscript and ASP.. I know. I don't like it either but it's the only
    > site I setup like this the rest are VB and asp..
    >
    > I tried a couple of the suggestions. It seems like for whatever reason
    > the variable isn't getting set.
    >
    > I tried using this:
    >
    > var MyVarMailto;
    > if ((Request.Form("LoanRequest") == "Under $250,000") &&
    > (Request.Form("Organization") == "1")) {
    > MyVarMailto = "";
    > }
    > else if ((Request.Form("LoanRequest") == "Over $250,000") &&
    > (Request.Form("Organization") == "1")) {
    > MyVarMailto = "";
    > }
    > else {
    > MyVarMailto = "";
    >
    > And also this:
    >
    > var MyVarMailto = "";
    > var MyAmt = Request.Form("LoanRequest");
    > var MyOrg = Request.Form("Organization");
    >
    > if (MyOrg == "1") {
    > if (MyAmt == "1") {
    > MyVarMailto = "";
    > } else if (MyAmt == "2") {
    > MyVarMailto = "";
    > }
    > }
    >
    > I shouldn't say the variable isn't getting set.. It's acting like none
    > of the conditions are matching and it's using the "ELSE" email
    > address.. The values are getting passed and that's why I'm confused.
    > Any ideas? Thanks!
    >


    Are you sure? Insert the following line after the "var" statements:
    alert("MyAmt=" + MyAmt + "\nMyOrg = " + MyOrg);
    what do you see?

    You may have to post a stripped version of your code.

    Does your page's filename have an ".asp" extension.
     
    McKirahan, Sep 20, 2006
    #7
  8. Lee Guest

    said:
    >
    >Yes, Jscript and ASP.. I know. I don't like it either but it's the only
    >site I setup like this the rest are VB and asp..
    >
    >I tried a couple of the suggestions. It seems like for whatever reason
    >the variable isn't getting set.
    >
    >I tried using this:
    >
    > var MyVarMailto;
    >if ((Request.Form("LoanRequest") == "Under $250,000") &&
    >(Request.Form("Organization") == "1")) {
    > MyVarMailto = "";
    >}
    >else if ((Request.Form("LoanRequest") == "Over $250,000") &&
    >(Request.Form("Organization") == "1")) {
    > MyVarMailto = "";
    >}
    >else {
    >MyVarMailto = "";
    >
    >And also this:
    >
    >var MyVarMailto = "";
    >var MyAmt = Request.Form("LoanRequest");
    >var MyOrg = Request.Form("Organization");
    >
    >if (MyOrg == "1") {
    > if (MyAmt == "1") {
    > MyVarMailto = "";
    > } else if (MyAmt == "2") {
    > MyVarMailto = "";
    > }
    > }
    >
    >I shouldn't say the variable isn't getting set.. It's acting like none
    >of the conditions are matching and it's using the "ELSE" email
    >address.. The values are getting passed and that's why I'm confused.
    >Any ideas? Thanks!


    Is this code executed on the client, or on the server?
    The client won't have a "Request" object, and you should be seeing error
    messages saying so.

    Is the code you've shown us inside a function definition? If so,
    are you returning MyVarMailto? It's declared as a local variable,
    so it won't be seen outside the function.


    --
     
    Lee, Sep 20, 2006
    #8
  9. Guest

    Hope you don't mind but I emailed you two ASP pages to the email
    address you have on this site. Figured it would be easier for you to
    see the entire code. Thanks
     
    , Sep 20, 2006
    #9
  10. Guest

    It's server side and not inside a function..

    > Is this code executed on the client, or on the server?
    > The client won't have a "Request" object, and you should be seeing error
    > messages saying so.
    >
    > Is the code you've shown us inside a function definition? If so,
    > are you returning MyVarMailto? It's declared as a local variable,
    > so it won't be seen outside the function.
    >
    >
    > --
     
    , Sep 20, 2006
    #10
  11. McKirahan Guest

    <> wrote in message
    news:...
    > Hope you don't mind but I emailed you two ASP pages to the email
    > address you have on this site. Figured it would be easier for you to
    > see the entire code. Thanks


    What would be "easier" for me would be to see less code.

    Try stripping the code down to the fewest lines that still has the
    problem. In this effort you may discover the problem yourself.

    If you haven't found the problem then post this code to the newsgroup.

    P.S. I accidentally deleted your email because it had an attachment.
     
    McKirahan, Sep 20, 2006
    #11
  12. Guest

    Ok here's the deal. The if/then/else code works fine.. What the problem
    seems to be is that when I put the cdonts code inside the "insert
    record" code the variable isn't getting the correct value.. However, if
    I put the cdonts code anywhere else the variable gets the correct value
    assinged to it.

    I have many pages setup with this same cdonts code and set in the same
    place. Totally stumped...
     
    , Sep 20, 2006
    #12
  13. McKirahan Guest

    <> wrote in message
    news:...
    > Ok here's the deal. The if/then/else code works fine.. What the problem
    > seems to be is that when I put the cdonts code inside the "insert
    > record" code the variable isn't getting the correct value.. However, if
    > I put the cdonts code anywhere else the variable gets the correct value
    > assinged to it.


    As I've said: "You may have to post a stripped version of your code."

    > I have many pages setup with this same cdonts code and set in the same
    > place. Totally stumped...


    Use an "include" file with the "same cdonts code" and change it once.
    <!--#include file="CDO_Code.asp"-->

    Construct the "body" in a variable then pass it in to a "include" function:

    email("",MyVarMailto,"BFS Loan Referral",MyVarBody)

    // CDO_Code.asp
    function email(eFrom,eTo,eSubj,eBody)
    var cdomail;
    cdomail = Server.CreateObject("cdonts.newmail");
    cdomail.from = eFrom;
    cdomail.to = eTo;
    cdomail.subject = eSubj;
    cdomail.body = eBody;
    cdomail.MailFormat = 0;
    cdomail.BodyFormat = 0;
    cdomail.send();
    }

    Prepare a standalone page to test it:

    <% @Language="JScript" %>
    <!--#include file="CDO_Code.asp"-->
    <html>
    <head>
    <title>CDO_Test.asp</title>
    <% var eFrom = "";
    var eTo = "... an email address ...;
    var eSubj = "BFS Loan Referral";
    var eBody = "... HTML source code ...";
    email(eFrom,eTo,eSubj,eBody)
    %>
    </head>
    </body>
    </html>

    I haven't tested this; also, I normally do server-side in VBScript.

    CDO.Message() has replaced CDONTS.NewMail():
    How do I send e-mail with CDO?
    URL:http://classicasp.aspfaq.com/email/how-do-i-send-e-mail-with-cdo.html


    Also, what if someone wants a loan of exactly $250,000?

    Size of Loan Request:&nbsp;
    <select name="LoanRequest" id="LoanRequest">
    <option value="null" selected>Select size of loan.
    <option value="1">Under $250,000
    <option value="2">Over $250,000
    </select>

    (Obviously I recovered you email and looked at the code.)
     
    McKirahan, Sep 20, 2006
    #13
  14. Guest

    Thanks but that is all beyond my level.. I don't understand why this
    one isn't working when all the others exactly like it are. The variable
    gets set as the wrong value when it's inside the insert code but gets
    set correctly when outside of it? I don't get it..

    What's even weirder is I can see the variable is gettin set correctly
    even when it's inside the insert code but for some reason it's not
    seeing that?

    How can this be explained?
     
    , Sep 20, 2006
    #14
  15. McKirahan Guest

    <> wrote in message
    news:...
    > Thanks but that is all beyond my level.. I don't understand why this
    > one isn't working when all the others exactly like it are. The variable
    > gets set as the wrong value when it's inside the insert code but gets
    > set correctly when outside of it? I don't get it..
    >
    > What's even weirder is I can see the variable is gettin set correctly
    > even when it's inside the insert code but for some reason it's not
    > seeing that?
    >
    > How can this be explained?


    Please quote what you are referring to.

    " ... isn't working ..." is not very helpful...

    It may be beyond your level now but just give it a try:

    Cut-and-paste my code to create two files:
    CDO_Code.asp and CDO_Test.asp
    post it to your Web server and visit CDO_Test.asp

    What happens?


    Also, since your original Subject line was
    "If / Then / Else Help Needed"
    and in a recent post you stated:
    "The if/then/else code works fine."
    then perhaps you should start a new post
    with your new peoblem.
     
    McKirahan, Sep 20, 2006
    #15
  16. Guest

    Ok. Thanks for the help.
     
    , Sep 21, 2006
    #16
    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. Troy Stanley - CyberWarehouse.com

    New to .NET - If Then Else condition against database results

    Troy Stanley - CyberWarehouse.com, Aug 14, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,345
    Brandon Wagner
    Aug 14, 2003
  2. -
    Replies:
    12
    Views:
    714
    Remon van Vliet
    Jun 15, 2005
  3. Bart Plessers \(artabel\)
    Replies:
    1
    Views:
    151
    Ray at
    Jul 17, 2003
  4. Replies:
    0
    Views:
    336
  5. Bill W.
    Replies:
    13
    Views:
    315
    Phillip Gawlowski
    May 9, 2011
Loading...

Share This Page