Adding values from Text Box form fields

Results 1 to 3 of 3

Thread: Adding values from Text Box form fields

  1. #1
    Renee W. Guest

    Default Adding values from Text Box form fields

    Hi,<BR>This is probably a newbie type question, but I&#039;ve been pondering it for hours and can&#039;t figure it out. I&#039;ve got two data fields from a form that I am looking at and this is what I need it to do:<BR><BR>If Value1 equals 100, I redirect to a confirmation page (this works fine). If Value 1 equals less than 100 and Value2 is blank, then I redirect back to the form for the user to enter a Value2 (this also works fine). If Value1 plus Value2 equal 100, they are redirected to a confirmation page (this isn&#039;t working). If Value1 plus Value2 are less than 100, then they are redirected to Page2 of the form (this isn&#039;t working). It appears that my two Values aren&#039;t adding together properly??<BR><BR>Here&#039;s the VBScript code that I have:<BR><BR>dim intValue1<BR>dim intValue2<BR>dim intTotal<BR><BR>intValue1 = Request.Form("value1")<BR>intValue2 = Request.Form("value2")<BR>intTotal = intValue1 + intValue2<BR><BR>if intValue1 = "100" then<BR>Response.Redirect("confirmation.asp")<BR>e nd if<BR><BR>if intValue1 &#060; "100" then<BR><BR> if intValue2= "" then<BR> Response.Redirect("Page1.asp#value2")<BR> end if<BR><BR> if intTotal = "100" then<BR> Response.Redirect("confirmation.asp")<BR> end if<BR> <BR> if intTotal &#060; "100" then<BR> Response.Redirect("Page2.asp")<BR> end if<BR><BR>end if<BR><BR>I&#039;d really appreciate any help I can get so that these two Values will add together and the appropriate redirection takes place. Thanks!!<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Adding values from Text Box form fields

    intValue1 = cdbl(Request.Form("value1"))<BR>intValue2 = cdbl(Request.Form("value2"))<BR><BR>response.write "IntValue1: " & intValue1 & "<BR>"<BR>Response.write "IntValue2: " & intValue2 & "<BR>"<BR><BR>all variables in asp are of type variant, you must explicity define what you want them to be right now, it could just be adding the values as strings instead of numbers<BR><BR>Hope this could help,<BR><BR>mj<BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: Adding values from Text Box form fields

    Don&#039;t forget to check if the fields are blank before doing the cdbl() function. If it&#039;s not a number, it will crash on you.<BR><BR>I usually do a statement like this:<BR>if IsNull(request("Field_Name")) then<BR> intVal1=0<BR>else<BR> intVal1=request("Field_Name")<BR>end if<BR><BR>I&#039;ve just recently had a lot of problems with that, and you definitely need that error checker.<BR><BR>Hope that helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts