Results 1 to 6 of 6

Thread: Default Button

  1. #1

    Thread Starter
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322

    Default Button

    Hi all,

    I understand that if I put a submit button on a page, that button becomes the default button (ie, just press enter and the submit button activates)

    However, if i want to do some validation before I submit the form, I use an input=button. However, when I do that, that button doesnt receive the focus automatically and the use has to manually click on it.

    The Q is, how do i enable the default status of a button just like it were a submit button ?

    Thanks.
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    HI SoftwareMaker,
    You dont really have to use input button, you can use submit button to do your validation.

    this is how i do my validation on most forms

    Code:
    <html>
    <head>
    <script>
    function validate()
    {
       if (some condition)
       {
        alert(msg);
        return false;
        }
    
        if (another condition)
        {
        alert (msg);
        return false;
    
    return true; 
    //if the functions returns true then the form will 
    //be submited otherwise the form wont be submited
    }
     </script>
    <body>
    
    <form action="submit.asp" onsubmit="return validate()">
    
    </form>
    </body>
    </html>
    Hope this helps
    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3
    Lively Member gigsvoo's Avatar
    Join Date
    Oct 2000
    Location
    Malaysia
    Posts
    109

    Post

    Normally I used this codes to do the form focus and validation as well:
    Code:
    <SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
    <!--
    
    Sub window_onload
    	Login.txtLogin.focus()
    End Sub
    
    
    Sub submit1_onclick
    	if len(login.txtPassword.value) < 6 then
    		Login.txtPassword.value = ""
    		msgbox "Password too short!"
    		exit sub
    	end if
    	login.submit()
    End Sub
    
    -->
    </SCRIPT>

  4. #4

    Thread Starter
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    Thanks guys for your tips.

    Thanks Daniel...so you are saying that once the function return false, the form wont get submitted ?
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  5. #5

    Thread Starter
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    Hi daniel,

    I am sorry BUT it seems to me that the input type=submit doesnt have a onsubmit event, so how now ?

    Thanks
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  6. #6

    Thread Starter
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    OOppps...Sorry my fault,

    I put on my glasses and actually saw that it is a form event not an input event. Sorry...
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

Posting Permissions

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



Click Here to Expand Forum to Full Width