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
    Sep 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Does button have to be type 'submit' ?

    Hi all, i have seen that there is an input type 'reset' which i presum clears all fields in a form? But anyway i did not know this existed and my implementation requires a bit more sophistication so i had already written code to do a custom reset of the boxes whilst keeping and updating certain key values. This works fine.

    My question is, for the actual 'submit' of the data in a form do i have to use a button of type 'submit'? It is actually better for me in this instance that i do not as the special message windows i am using will close - and in the case of errors in the user input this is not desirable - so i have written the error handling etc with window staying open in mind, so that user can correct their errors and resubmit.

    To accomplish this i changed my input into type 'button' and it works fine

    When i click 'the submit button' it checks fields for valid data first - can i use its return value to somehow activate or not the actual form data sending?

    Like i have

    Code:
    <input type = "button" style = "font-size:18;" value= "  Submit  "onclick = "CheckValid()"/>
    I could be calling 'SendForm()' or something here instead and have check valid called from within SendForm() i norder to determin it's return type, how can i use this to decide if the form data is valid to send or not? and how could i use the return value in the html like this?

    should i A: think it is possible to send all the data from within the onclick function so i use that to decide if it gets sent from internal calls there and display thank you message if so, if not display error message.

    should i B:

    Disable the sending button until the fields contain valid data? Or use a second button to confirm data then allow a submit button to be pressed?

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,989
    Thanks
    56
    Thanked 557 Times in 554 Posts
    if your checkValid function does what it seems to, why not just add an if else in there once the validation is complete?

    Code:
    if (valid==true) {
    document.myform.submit();
    } else  {
    //prompt user for more info
    }

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    if your checkValid function does what it seems to, why not just add an if else in there once the validation is complete?

    Code:
    if (valid==true) {
    document.myform.submit();
    } else  {
    //prompt user for more info
    }
    thats great - - Thats what i was looking for, now i know there is a document property that can submit the data then i can call that conditionally, and that is sorted.


  •  

    Posting Permissions

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