By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,576 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,576 IT Pros & Developers. It's quick & easy.

form submission using javascript

P: 7
Hi All,

Is there a way of submitting a form using javascript and without manual click on submit button..?
the textbox is being filled dynamically and as soon as it gets a value the form should get submitted. Have anyone tried this before?

It shouldn't be using PHP or ASP or other things.. only HTML and Javascript.

Thanks,
Imtiyaz Quraishi
Mar 22 '11 #1
Share this Question
Share on Google+
8 Replies


Dormilich
Expert Mod 5K+
P: 8,639
to submit a form by JavaScript, use the formís .submit() method. how to trigger that, is a different matter.
Mar 22 '11 #2

P: 7
Thanks Niheel for editing and adding wht I forgot..
Thanks Dormilich, but can you let me know what that "Different Matter" could be..?
Mar 22 '11 #3

Dormilich
Expert Mod 5K+
P: 8,639
that "different matter" is how you call form.submit(). you do not necessarily need a button for that, thus possibilities are numerous.
Mar 22 '11 #4

P: 7
A couple of examples of those would be appreciated.. thanks..
Mar 22 '11 #5

Dormilich
Expert Mod 5K+
P: 8,639
e.g. something as fancy as when a field is filled:
Expand|Select|Wrap|Line Numbers
  1. field_ref.addEventListener("change", form_ref.submit, true);
Mar 22 '11 #6

P: 7
Thanks Dormilich but as you might have noticed, from my comments and questions, that I'm a newbie when it comes to javascript. It'll be grateful if you can give me a little detailed example which I can understand or elaborate the above one?
Mar 22 '11 #7

Dormilich
Expert Mod 5K+
P: 8,639
(actually, when I re-read your OP, my example was quite close).

for some explanation of the code
Expand|Select|Wrap|Line Numbers
  1. field_ref.addEventListener("change", form_ref.submit, true);
field_ref is the JavaScript object of your text field.
change is the event type used (there are some other possible types, but I’ve seen this as the best suited)
form_ref is the is the JavaScript reference to the form element
addEventListener is used for standard event handling (does not work in IE)

for getting the element references (field_ref, form_ref) you typically use document.getElementById()
Mar 22 '11 #8

P: 7
Thanks once again, will try this tonight and will let you know.. :)
Mar 22 '11 #9

Post your reply

Sign in to post your reply or Sign up for a free account.