• 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

multiple task in one method in javascript

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code here:






and




so , here this is button type, then only I could use onclick, but I want to know if this was a text box, how could I use onclick here? please help me.The same situation I am facing , but the difference is my case is all text boxex are input text boxes, so how can I use in that case?
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't the javascript function need to know what value is pressed? So the javascript function should have a parameter.





In your example, you may want to echo the val in the javascript (using alert) to check that the value "gold" is really passed into the function. If everything goes well, the goldsystem.jsp is submitted.

Using JQuery would make it much easier I think.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to know only , that I have same situation but this time I used input textbox rather button, so how can I put onclick on that input textbox?
 
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

sarojni agrwal wrote:so how can I put onclick on that input textbox?


The same way that you do on any other element. But to what purpose?

Your post so far doesn't really let us know what you are actually trying to accomplish.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sarojni agrwal wrote:so how can I put onclick on that input textbox?


The real question is: Why don't you want a visible submit control? Users can submit an HTML form simply by pressing "Enter" while the focus is inside a text input field (not in a textarea) without ever clicking on the submit control. More code is needed once you remove the submit element from the form - i.e. an event handler would have to monitor key presses to intercept "Enter" and coordinate the submit programmatically (which won't necessarily work for tablets anyway).

If absolutely necessary, "hide" the submit control and leave most of the work to the browser:

HTML forms guide - Web developer guides | MDN
submit - Event reference | MDN
html - Submitting a form by pressing enter without a submit button - Stack Overflow


 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


this is my code, in which I want to check the numbers in debit card and other fields also, but I am able to check only one, because, in input field onclick function is not used, if there are buttons rather than text boxes then I will handle, by put onclick on every button , but how can I handle here by input text texts?

if only this means only one then I will handle like this:

Screenshot_8.png
[Thumbnail for Screenshot_8.png]
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sarojni agrwal wrote:in which I want to check the numbers in debit card and other fields also, but I am able to check only one, because, in input field onclick function is not used, if there are buttons rather than text boxes then I will handle, by put onclick on every button , but how can I handle here by input text texts?


What makes you think that you need a separate event listener for each input text field? When the user clicks the submit button an event listener on the form element will fire. event.target will be form element and you can easily get a hold of each of the form's input fields inside the listener and retrieve their values for validation.

In the above code I got the value of the "search" text input element. If there were more text input elements I could get their values in exactly the same manner - no need for separate event listeners.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can not understand this coding, I read some JavaScript and JQuery, but where should I read this type of coding, and yes I want separate checking for each input text when I click submit...
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is an example: Event Handling Using addEventListener.
Note that the code in the example uses this while the code above above uses event.target inside the event handler. There is a subtle difference between the two:
  • inside an event handler this refers to the element the event handler is attached to
  • while event.target is the element the event originated from
  •  
    sarojni agrwal
    Ranch Hand
    Posts: 100
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    can anyone explain me why alert not active when requirement not met and submit the button , few days ago alert works , why this time not working?

     
    Peer Reynders
    Bartender
    Posts: 2968
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
  • You have been repeatedly asked to indent and format your code properly - it makes it easier to read - if you would indent and format it properly it should occur to you that the second half of the code isn't even part of the event handler.


  • You really need to look over the "Debugging" section of the Javascript Links (Wiki forum at Coderanch). If you use Google Chrome/Chromium: Chrome DevTools Overview - Google Chrome: Debugging JavaScript, Debugging JavaScript - Google Chrome: Debugging with breakpoints. The console of the development tools would have immediately told you that the return on line 47 is illegal (because the code is not inside a function).


  • The browser ignores your script because your script failed during the page load - so as far as the browser is concerned the script doesn't exist, so it goes straight to submit because that is what the HTML is designed to do.


  • In more recent years it has been considered bad practice to use inline JavaScript event handlers or on-event handlers. You were made aware of the alternative in your validation in javascript topic.
  •  
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic