• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

onClick event question.....

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one quick question...
How come when i input something in textbox and with my mouse if i click the submit button, it shows me the alert...
But if i input a value in textbox and then press the "enter" key it shows me a blank screen....
I tried with keyPress event and same thing...
Any help will be greatly appreciated...
Thanks...
Also in the below HTML code...I am adding "s" to the html code.....Just erase it...Thansk...
<htmls>
<heads>
<titles>Untitled Document</titles>
<scripts>
function f(){
alert(document.form1.text1.value);
}
</scripts>
</heads>
<bodys>
<form name="form1"s>
<input name="text1" type="text"s>
<input name="submitButton" type="submit" value="Submit" onClicks="f();">
</forms>
</bodys>
</htmls>
 
sam patel
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok...
I kind of figured it out....
Because when i press enter while in textbox the focus in not on the submitbutton...

Is there any way i can set the focus on the submit button as soon as i am done inputting values in textbox...
Any help will be greatly appreciated...
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, after counting characters or whatever else constitutes "done entering text", you can move focus to the button with:

But, I'd like to ask what you are trying to accomplish in the first place. There may be an easier way.
For example, if you simply want your Javascript function to be called prior to form submission, rather than using the onclick handler of the button, you can use the onsubmit handler of the form (which will get activated regardless of how the form is submitted).
hth,
bear
 
sam patel
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
For example, if you simply want your Javascript function to be called prior to form submission, rather than using the onclick handler of the button, you can use the onsubmit handler of the form (which will get activated regardless of how the form is submitted).



Hi Thank you for your reply...but how can i do that you mentioned above in quote...
A simple example would be greatly appreciated....
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<form onsubmit="return TestForm()">
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Eric said. Additionally, when you use the format:

If you return the value true from the function, the form will be submitted as usual. If you return false, form submission is cancelled. This makes the onsubmit handler a great place to do form validation just prior to form submission.
The handler will be called regardless of whether the form submission is initiated by a click of a submit button, or by the use of the Enter key.
Note that the handler is not called if the form is submitted under Javascript control; a la document.myForm.submit().
hth,
bear
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic