Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

HTML +Javascript submit query??

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my application i have taken a submit button in my html form but it gets submitted when the button is CLICKED that is i have kept a onClick event on that button & the type of button is "button" not "submit" because if i keep it as submit then some problem arises in my application thats when i click on that button using mouse the form gets submitted 2 times.

So what i want to do is i want to keep this onclick event active but if the user presses enter key then also the function called on onClick event should get called..

So how to do this thing??


Thanks,
Jignesh
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though I partially understood you question, you can use onsubmit event handler of the form tag.

You need to use the "submit" button and you need to write the function to handle the onsubmit event of the form. So in both the cases (click of submit button or enter key) will trapped. On the event handler, if you dont want the form to get submitted, you can return false from the event handler.

Hope this helps.
 
Where does a nanny get ground to air missles? Protect this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic