www.webdeveloper.com
Results 1 to 3 of 3

Thread: onchange and submit button contention

  1. #1
    Join Date
    May 2011
    Posts
    2

    onchange and submit button contention

    I have a form with onchange events set on some of the text fields so that calculations can be made. By clicking the Submit button, the form data is then saved to the database. This all works fine as long as you leave a text field by tabbing to or clicking in another field before clicking Submit. However if you make a change in a text field and then directly click the Submit button, the onchange event occurs but the form submission does not. I have tried other types of events such as onfocus, onblur, etc. in place of onchange. I have also tried using the setTimeout function, with various time values, to cause a delay between the onchange and submit events. But the results are the same. Any advice would be appreciated. Thanks.

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,355
    What does your <form> tag look like?

  3. #3
    Join Date
    May 2011
    Posts
    2
    The form tag looks like
    <form id='inv_form' name='inv_form' method='post' action='new_inv.php' onsubmit=’return checkform( this )’>

    The onchange events on the form's text boxes look like
    onchange=’submit()’

    Upon onchange and onsubmit, the script calls itself (new_indv.php). In the case that the submit button is clicked, the data validation script 'checkform' should run prior. In new_indv.php, I check to see if the submit button, named submit1, has a value which indicates it was clicked. If it does, the script save_inv.php is called to save the final data to the database. If the submit button was not clicked, it was an onchange event and the new_indv.php script continues with running calculations and populating the form.

    These events happen as they should if they occur separate from each other. But if you change a text box and directly click the submit button (without tabbing or clicking another field first), the onchange occurs but the final form submission does not.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles