Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form onsubmit: one function for the website

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
0
0
BE
Hello,

Just wondering if it's possible to write one onsubmit function for every form in my website. So that the function is called when a form is submitted. I don't want to add onsubmit in every form tagg.

I just want to display a message when a form is submitted. Something like 'data is submitted, please wait'.

So I would add to the page head something:
document.form.onSubmit = alert('please wait');

I just have one index.php that is called and that's including content from other pages. So you understand that I would only need to declare this function in the index-page and that it would call the function everytime a form is submitted.

(I hope I explained it clear)

visit my website at
 
Hi

Like this ?
Code:
function whatever()
{
  alert('submitting')
}
window.onload=function() {
  for (var i=0,l=document.forms.length;i<l;i++) document.forms[i].onsubmit=whatever
}

Feherke.
 
Yes something like that. One way or the other it's calling the function when it loads the page? So it's not working.

Anyway you gave me a good direction and I managed to do it.
I'm not explaining how because it was not with javascript, I'm working with the Zend framework and I could easy add the onsubmit to all forms...

Just another question now. I submit my form with javascript. So I have a button with onClick="javascript:submit();". Is it normal that when you submit a form like that the 'onSubmit' isn't called?

And one final question. I want to do something similar but then always when a user clicks e.g. a link. So he clicks, page start going to the link... so would be nice to get a message. Is this easy to do?

visit my website at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top