Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question disabling buttons after a submit

    What I'm looking for: I have a page that has multiple submit buttons on it. When the user clicks on a submit button, I need for two things to happen; 1-all submit buttons to be disabled and 2-the value of the submit button that the user clicked to stay in the value field so when the webpage returns control back to my program running in the background, it knows which button was clicked. My problem is when I go to disable all of the submit buttons using the following code:

    function disablebuttons()
    {
    for(i=0; i<document.forms[0].elements.length; i++)
    {
    if (document.forms[0].elements[i].type == "submit" || document.forms[0].elements[i].type == "button")
    {
    document.forms[0].elements[i].disabled = "true";
    }
    }
    document.forms[0].submit();
    }

    it disables all the buttons on the screen, but it also clears out all of their values so my background program has no clue which button was pressed. I can get around this by creating a hidden field on the webpage and calling the following code in the onclick() of each button:

    function leaving2(btn)
    {
    document.forms[0].answer.value = btn.name;
    disablebuttons();
    }

    I pass the name of the button clicked into this hidden field, disable the buttons, and then in my background program, I test against the hidden field to see which button was clicked. The only bad thing about this is that I have over 100 webpages and the process to add a new field onto each of those pages would be very time consuming.

    So my question is: Is there a easier solution to where the value of the button clicked can stay intact despite it being disabled or am I stuck with my solution?

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Doesn't submitting a form refresh the page by default? The page refreshing could be the problem.

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    My background program checks the values of the page before it is refreshed though. I've done the following to where if I had a button with an id of "btn1", I could automatically simulate that it was clicked by doing the following javascript:

    document.forms[0].btn1.value = "go";document.forms[0].submit();

    The above code works. When I go to disable all buttons on the screen so an impatient user can't double click, that's when the value is getting cleared out and I haven't found a way to put the value back in without having the button get reactivated.


  •  

    Posting Permissions

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