#1
  1. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2007
    Posts
    44
    Rep Power
    11

    Javascript -- Disable Button Until Page Loads


    I have no experience with javascript, but am hoping this is an easy question.

    I have a search page that involves three forms. The user makes a selection in the first drop down box, and a little bit of javascript submits the form. The option the user has selected in the first drop down box dictates what is displayed in the second drop box, and so on down the line until the last dropdown box, after which is a GO button that queries the database and returns the results. The user may use one or all three dropdown boxes to form their search.

    The problem I'm encountering is that users on a slow connection can hit the go button before the page has finished loading their selection from one of the dropdown boxes. In this case, the page will not display the correct results for them.

    I'm wondering if there is some way to disable the go button while the page is loading?

    Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Posts
    1,895
    Rep Power
    310
    Originally Posted by geog272
    I have no experience with javascript, but am hoping this is an easy question.

    I have a search page that involves three forms. The user makes a selection in the first drop down box, and a little bit of javascript submits the form. The option the user has selected in the first drop down box dictates what is displayed in the second drop box, and so on down the line until the last dropdown box, after which is a GO button that queries the database and returns the results. The user may use one or all three dropdown boxes to form their search.

    The problem I'm encountering is that users on a slow connection can hit the go button before the page has finished loading their selection from one of the dropdown boxes. In this case, the page will not display the correct results for them.

    I'm wondering if there is some way to disable the go button while the page is loading?

    Thanks!
    Code:
    <input type="submit" id="SubmitButton" name="SubmitButton" disabled="disabled">
    Then onload
    Code:
    formObj.SubmitButton.disabled = false;
  4. #3
  5. short arse brainiac
    ASP Adventurer (500 - 999 posts)

    Join Date
    Jun 2005
    Location
    Leeds UK
    Posts
    577
    Rep Power
    40
    that would only run on load not when loaded, best practice would be either to add a library like jquery and run a check to see if it is all loaded or run javascript at the bottom of your page:

    put a span where you want button to go

    at end of page, last to load add this javascript

    Code:
    function loaded(){
    document.getElementById("myspanid").innerHTML='<input type="submit" name="submit" value="click to continue" />';
    }
    
    setTimeout("loaded()",2000);
    should just about do it

    Comments on this post

    • Shadow Wizard disagrees : sorry but I totally disagree with this approach. about as bad as you can have.
    A girl's best asset is her 'lie'ability.

    For Sale: Parachute. Only used once, never opened, small stain.

    that fold thing
  6. #4
  7. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2007
    Posts
    44
    Rep Power
    11
    Thanks for the advice and code samples...

    I do actually want the button to be disabled only when the page is refreshing...

    I haven't gotten it to work yet, but am closer with the help of your examples!
  8. #5
  9. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    the code Jonathan gave you is the correct code.
    if it's not working, you have to find out why, and fix it.
  10. #6
  11. No Profile Picture
    Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Posts
    1,895
    Rep Power
    310
    Originally Posted by geog272
    Thanks for the advice and code samples...

    I do actually want the button to be disabled only when the page is refreshing...

    I haven't gotten it to work yet, but am closer with the help of your examples!
    Post your code and we may be able to assist.
  12. #7
  13. Cunning Linguist
    ASP High Scholar (3500 - 3999 posts)

    Join Date
    Mar 2005
    Location
    I used to live at home, now I stay at the house
    Posts
    3,580
    Rep Power
    433
    Originally Posted by minus4
    that would only run on load not when loaded
    That's not exactly true. The onload event only fires after the entire
    document has finished loading.
    Support requests via PM will be ignored!
    Route of Queue | The General FAQ Thread | HOW TO POST A QUESTION

    Perfectly Impossible - is the eagerly awaited debut release from Jayne Sarah - please buy it - it's really good!

  14. #8
  15. Moderator From Beyond
    ASP Mastermind (5000+ posts)

    Join Date
    Sep 2004
    Location
    Israel
    Posts
    31,135
    Rep Power
    2925
    Originally Posted by ChiefWigs1982
    That's not exactly true. The onload event only fires after the entire
    document has finished loading.
    lol I wish that was the only wrong part of his post..
    anyhow, this is true: onload will fire only after all images finished
    loading etc and sometimes it can take more than two seconds.

Similar Threads

  1. Replies: 2
    Last Post: May 18th, 2006, 08:56 PM
  2. Stop the page going back to the top when a button clicked?
    By sandy123 in forum .NET Development
    Replies: 2
    Last Post: March 14th, 2006, 02:50 AM
  3. load a new page through a button??
    By Shams Al in forum .NET Development
    Replies: 4
    Last Post: August 20th, 2004, 01:50 PM
  4. opening another asp page on button click
    By bobthecow in forum ASP Development
    Replies: 3
    Last Post: July 28th, 2004, 03:12 PM
  5. Problem passing a value to an asp.net page
    By PalmDrac in forum .NET Development
    Replies: 4
    Last Post: March 5th, 2003, 02:02 AM

IMN logo majestic logo threadwatch logo seochat tools logo