SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Port Richey, FL
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Disabling a button ruins my Request.Form?!

    (This is posted in Javascript because as far as I can tell the JS code is what is causing the problem)

    I'm working on a payment page in Classic ASP.. when the user presses the 'Process' button, I postback the page and capture the variables. To avoid them pressing Process more than once I want to disable it in javascript.. but for some reason this causes the page to ignore my ASP code. Here is the relevant bits (both ASP and Javascrpt):

    ASP
    Code:
        If Trim(Request.Form("checkoutButtons")) = "Process" Then
            
            Dim temp_first, temp_last, temp_phone, temp_street, temp_street2, _
                temp_city, temp_state, temp_zip, temp_country, temp_cardType, _
                temp_cardNumber, temp_cvv, temp_expMonth, temp_expYear, temp_amount, actionCode
                
            ' Store form variables           
            temp_first = UCase(Request.Form("firstName"))
            temp_last = UCase(Request.Form("lastName"))
            temp_phone = UCase(Request.Form("phoneNumber"))
            temp_street = UCase(Request.Form("street"))
            temp_street2 = UCase(Request.Form("street2"))
            temp_city = UCase(Request.Form("city"))
            temp_state = UCase(Request.Form("state"))
            temp_zip = UCase(Request.Form("zipCode"))
            temp_country = UCase(Request.Form("country"))
            temp_cardType = UCase(Request.Form("cardType"))
            temp_cardNumber = UCase(Request.Form("cardNumber"))
            temp_cvv = UCase(Request.Form("cvv"))
            temp_expMonth = UCase(Request.Form("expirationMonth"))
            temp_expYear = UCase(Request.Form("expirationYear"))
            temp_amount = CDbl(Request.Form("amount"))
            actionCode = "Sale"
            
            ' test - write out
            Response.Write temp_first & " " & temp_last & " " & temp_phone & " " & temp_street & " " & _
                temp_street2 & " " & temp_city & " " & temp_state & " " & temp_country & " " & " " & _
                temp_cardType & " " & temp_cardNumber & " " & temp_cvv & " " & temp_expMonth & " " & _
                temp_expYear & " " & temp_amount & " " & actionCode
        End If
    JavaScript
    Code:
        function form_onSubmit()
        {
            if (checkForm() == false)
            {
                return false;
            }
            else
            {
                document.forms.paymentForm.checkoutButtons[0].disabled = true;
                return true;
            }
        }
    My button has "return form_onSubmit()" in its onsubmit event (the checkForm function is validation and not relevant) for validation purposes. I've discovered that if I remove the document.forms.paymentForm.checkButtons[0] line, then my test Response.Write works and I can see the values I entered on the form. When that line is there, however, the page posts (clearing the values) but displays nothing; it compltely ignores my If.. Then clause.

    Am I doing something wrong? Does disabling the button prevent it from being seen on a postback?

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you disable a submit button in javascript it will not send its VALUE to the POST page. In the asp you are checking the value of Request.Form("checkoutButtons"), and it is empty because it's disabled.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Port Richey, FL
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So is there any way then to do this? Business rules require the button to be disabled when the user clicks it to avoid them pressing it multiple times and billing themselves more than once.

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    add a hidden value to the form, and in your ASP check for that instead of the submit button's value


Bookmarks

Posting Permissions

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