Connecting Tech Pros Worldwide Help | Site Map

Dynamic form submission through Java Script

Newbie
 
Join Date: Dec 2007
Posts: 2
#1: Dec 20 '07
please some one give me a simple code for this
Ranjan kumar Barik's Avatar
Member
 
Join Date: Aug 2007
Posts: 95
#2: Dec 20 '07

re: Dynamic form submission through Java Script


Quote:

Originally Posted by chanchal21pes

please some one give me a simple code for this

Hi,
You can define a function like this;
Expand|Select|Wrap|Line Numbers
  1. function submit()
  2. {
  3.     document.form.submit();
  4. }
  5.  
inside the script tag or in your javascript file and call it anywhere you like, to submit the page.

Happy Programming !
:)
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#3: Dec 21 '07

re: Dynamic form submission through Java Script


You can also put this just inside nearly any HTML tag:
Expand|Select|Wrap|Line Numbers
  1. onClick="document.form.submit()"
  2.  
Ranjan kumar Barik's Avatar
Member
 
Join Date: Aug 2007
Posts: 95
#4: Dec 22 '07

re: Dynamic form submission through Java Script


Quote:

Originally Posted by jhardman

You can also put this just inside nearly any HTML tag:

Expand|Select|Wrap|Line Numbers
  1. onClick="document.form.submit()"
  2.  

Yes,
you are right. But I think, if we have to submit after validating some form fields then it would be better to have a user defined function for validating and then submitting.

And I am not sure but this one;
Expand|Select|Wrap|Line Numbers
  1. onClick="this.submit()"
may work.

Thanks.
Merry Christ mass!
:)
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#5: Dec 22 '07

re: Dynamic form submission through Java Script


Quote:

Originally Posted by Ranjan kumar Barik

And I am not sure but this one;

Expand|Select|Wrap|Line Numbers
  1. onClick="this.submit()"
may work.

If the element is in a form, it would work like this:
Expand|Select|Wrap|Line Numbers
  1. onClick="this.form.submit()"
you need to reference the form since it is the form that is submitted. Good point about the function, by the way.

Jared
Ranjan kumar Barik's Avatar
Member
 
Join Date: Aug 2007
Posts: 95
#6: Dec 26 '07

re: Dynamic form submission through Java Script


Quote:

Originally Posted by jhardman

If the element is in a form, it would work like this:

Expand|Select|Wrap|Line Numbers
  1. onClick="this.form.submit()"
you need to reference the form since it is the form that is submitted. Good point about the function, by the way.

Jared

Thanks a lot.
Have a good day!
:)
Reply


Similar JavaScript / Ajax / DHTML bytes