Forum Moderators: open
I don't think popping up an alert when the form is submitted is a good idea, since if the form is submitted to a CGI app or other server-side script you should get a confirmation screen back anyway, and that should say "Thanks". A JavaScript alert is just something else to click on, and it's modal, meaning the form won't be submitted until the OK button is pressed. That just wastes time.
However, the workaround is simple: use the onsubmit handler of the form element. So your <form> tag should look like this:
<form onsubmit="alert('Thanks'); return true;" action="...">
This will work even if the user submits the form without hitting the submit button (for example, by hitting the Enter key).
Notice I have included return true in the event handler. Strictly speaking this is unnecesary, but hints at what this handler is actually for: if you return false, the form will not be submitted. This is what is happening when you have a form validation script:
<form onsubmit="return check(this);" action="...">
This will pass the form to a function called check() which you must write yourself. You arrange things so that check() returns false if the form contains errors, true if it is error-free and can be submitted.
Rewboss,
That is the fix I'm looking for. The reason I use the Alert as such, is that it is part of a "Add to Cart" button. When a customer presses it, it runs a ASP script that adds the item to their cart. It then returns to the same page. You could display a message on the same page, but customers tend to miss the text within all the other text on that page. So, the pop-up solves this problem by focusing attention. I could return to a page that just has the message indicating the item was added to the cart, but then naviagation becomes more difficult, as back would need to be clicked "twice" instead of once to return to the page prior to the product page.
Thanks,
Also, depending on what it is you're actually selling, you have to bear in mind that constantly getting popup alerts and having to bat them down (that's what it feels like) is intensely annoying. The reason they are called "alerts" is because they are designed to alert the user of some critical problem. Hence the exclamation mark and the loud Bong! noise you get.